public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) { if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout"); } if (string.IsNullOrEmpty(tipText)) { throw new ArgumentException("tipText"); } if (DesignMode) { return; } if (created) { NativeMethods.NotifyIconData data = new NativeMethods.NotifyIconData(); if (window.Handle == IntPtr.Zero) { window.CreateHandle(new CreateParams()); } data.Window = window.Handle; data.ID = id; data.Flags = NativeMethods.NotifyIconDataFlags.Info; data.TimeoutOrVersion = timeout; data.InfoTitle = tipTitle; data.Info = tipText; data.InfoFlags = (int)tipIcon; NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Modify, data); } }
private void UpdateNotifyIcon(bool showNotifyIcon) { if (DesignMode) { return; } lock (syncObj) { window.LockReference(showNotifyIcon); NativeMethods.NotifyIconData data = new NativeMethods.NotifyIconData(); data.CallbackMessage = WM_TRAYMOUSEMESSAGE; data.Flags = NativeMethods.NotifyIconDataFlags.Message; if (showNotifyIcon && window.Handle == IntPtr.Zero) { window.CreateHandle(new CreateParams()); } data.Window = window.Handle; data.ID = id; if (icon != null) { data.Flags |= NativeMethods.NotifyIconDataFlags.Icon; data.Icon = icon.Handle; } data.Flags |= NativeMethods.NotifyIconDataFlags.Tip; data.Tip = text; if (showNotifyIcon && icon != null) { if (!created) { int i = 0; do { created = NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Add, data); if (!created) { System.Threading.Thread.Sleep(200); i++; } } while (!created && i < 40); } else { NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Modify, data); } } else { if (created) { int i = 0; bool deleted = false; do { deleted = NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Delete, data); if (!deleted) { System.Threading.Thread.Sleep(200); i++; } } while (!deleted && i < 40); created = false; } } } }
public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) { if (timeout < 0) throw new ArgumentOutOfRangeException("timeout"); if (string.IsNullOrEmpty(tipText)) throw new ArgumentException("tipText"); if (DesignMode) return; if (created) { NativeMethods.NotifyIconData data = new NativeMethods.NotifyIconData(); if (window.Handle == IntPtr.Zero) window.CreateHandle(new CreateParams()); data.Window = window.Handle; data.ID = id; data.Flags = NativeMethods.NotifyIconDataFlags.Info; data.TimeoutOrVersion = timeout; data.InfoTitle = tipTitle; data.Info = tipText; data.InfoFlags = (int)tipIcon; NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Modify, data); } }
private void UpdateNotifyIcon(bool showNotifyIcon) { if (DesignMode) return; lock (syncObj) { window.LockReference(showNotifyIcon); NativeMethods.NotifyIconData data = new NativeMethods.NotifyIconData(); data.CallbackMessage = WM_TRAYMOUSEMESSAGE; data.Flags = NativeMethods.NotifyIconDataFlags.Message; if (showNotifyIcon && window.Handle == IntPtr.Zero) window.CreateHandle(new CreateParams()); data.Window = window.Handle; data.ID = id; if (icon != null) { data.Flags |= NativeMethods.NotifyIconDataFlags.Icon; data.Icon = icon.Handle; } data.Flags |= NativeMethods.NotifyIconDataFlags.Tip; data.Tip = text; if (showNotifyIcon && icon != null) { if (!created) { int i = 0; do { created = NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Add, data); if (!created) { System.Threading.Thread.Sleep(200); i++; } } while (!created && i < 40); } else { NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Modify, data); } } else { if (created) { int i = 0; bool deleted = false; do { deleted = NativeMethods.Shell_NotifyIcon( NativeMethods.NotifyIconMessage.Delete, data); if (!deleted) { System.Threading.Thread.Sleep(200); i++; } } while (!deleted && i < 40); created = false; } } } }
private void UpdateNotifyIcon(bool showNotifyIcon) { if (DesignMode) { return; } lock (syncObj) { window.LockReference(showNotifyIcon); NativeMethods.NotifyIconData data = new NativeMethods.NotifyIconData(); data.CallbackMessage = WM_TRAYMOUSEMESSAGE; data.Flags = NativeMethods.NotifyIconDataFlags.Message; if (showNotifyIcon && window.Handle == IntPtr.Zero) { window.CreateHandle(new CreateParams()); } data.Window = window.Handle; data.ID = id; if (icon != null) { data.Flags |= NativeMethods.NotifyIconDataFlags.Icon; data.Icon = icon.Handle; } data.Flags |= NativeMethods.NotifyIconDataFlags.Tip; data.Tip = text; if (showNotifyIcon && icon != null) { if (!created) { // try to modify the icon in case it still exists (after WM_TASKBARCREATED) if (NativeMethods.Shell_NotifyIcon(NotifyIconMessage.Modify, data)) { created = true; } else // modification failed, try to add a new icon { int i = 0; do { created = NativeMethods.Shell_NotifyIcon(NotifyIconMessage.Add, data); if (!created) { System.Threading.Thread.Sleep(200); i++; } } while (!created && i < 40); } } else // the icon is created already, just modify it { NativeMethods.Shell_NotifyIcon(NotifyIconMessage.Modify, data); } } else { if (created) { int i = 0; bool deleted; do { deleted = NativeMethods.Shell_NotifyIcon(NotifyIconMessage.Delete, data); if (!deleted) { System.Threading.Thread.Sleep(200); i++; } } while (!deleted && i < 40); created = false; } } } }