private static void DoHiddenIconAdded(NativeMethods.NOTIFYICONDATA iconData, Tuple <int, uint> tuple) { if (HiddenIconAdded != null) { HiddenIconAdded(iconData, tuple); } }
public void ShowBalloonTip(int timeout, string tipTitle, string tipText, NotifyBalloonIcon tipIcon) { if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout", timeout, SR.NotifyIcon_NoNegativeTimeout); } ArgumentValidator.NotNullOrEmptyString(tipText, "tipText"); ArgumentValidator.EnumValueIsDefined(typeof(NotifyBalloonIcon), tipIcon, "tipIcon"); if (_iconCreated) { _allWindowsPermission.Demand(); var pnid = new NativeMethods.NOTIFYICONDATA { hWnd = _hwndSource.Handle, uID = _id, uFlags = NativeMethods.NotifyIconFlags.Balloon, uTimeoutOrVersion = timeout, szInfoTitle = tipTitle, szInfo = tipText, dwInfoFlags = (int)tipIcon }; NativeMethods.Shell_NotifyIcon(1, pnid); } }
private static void TrayIconAdded(NativeMethods.NOTIFYICONDATA iconData) { // TODO: GUID not taken into account var tuple = Tuple.Create(iconData.hWnd, iconData.uID); // add to visible or to hidden icons if (!SystemAndProcessInformation.isAtLeast7 || SystemTray.ContainsButton(SystemAndProcessInformation.trayHandle, (IntPtr)iconData.hWnd, iconData.uID)) { IconAdded(iconData, tuple); } else { DoHiddenIconAdded(iconData, tuple); } }
private void OnIconModified(NativeMethods.NOTIFYICONDATA iconData, Tuple <int, uint> tuple) { Tuple <SystemTray.TrayIcon, PictureBox, ToolTip> trayIcon; if (icons.TryGetValue(tuple, out trayIcon) && UpdateIconData(trayIcon, iconData)) { RepositionControls(left, right); if (TrayIconVisible(trayIcon.Item1)) { bar.DoWidgetControlsChanged(this, Enumerable.Empty <PictureBox>(), new[] { trayIcon.Item2 }); } else { bar.DoWidgetControlsChanged(this, new[] { trayIcon.Item2 }, Enumerable.Empty <PictureBox>()); } } }
private void OnIconAdded(NativeMethods.NOTIFYICONDATA iconData, Tuple <int, uint> tuple) { if (!icons.ContainsKey(tuple)) { var trayIcon = new SystemTray.TrayIcon { hWnd = (IntPtr)iconData.hWnd, id = iconData.uID }; var pictureBox = CreatePictureBox(trayIcon); var t = Tuple.Create(trayIcon, pictureBox, CreateToolTip(pictureBox, trayIcon.tooltip)); UpdateIconData(t, iconData); icons[tuple] = t; if (TrayIconVisible(trayIcon)) { RepositionControls(left, right); bar.DoWidgetControlsChanged(this, Enumerable.Empty <PictureBox>(), new[] { pictureBox }); } } }
private void Initialize() { // init struct _NID = new NativeMethods.NOTIFYICONDATA(); _NID.hWnd = _messages.Handle; _NID.szTip = String.Empty; _NID.szInfo = String.Empty; _NID.szInfoTitle = String.Empty; _NID.cbSize = Marshal.SizeOf(typeof(NativeMethods.NOTIFYICONDATA)); _NID.dwState = 0; _NID.dwStateMask = 0; _NID.uFlags = NativeMethods.NIF_ICON | NativeMethods.NIF_TIP | NativeMethods.NIF_MESSAGE; _NID.uCallbackMessage = NativeMethods.WM_NOTIFYICONCALLBACK; _NID.uVersion = NativeMethods.NOTIFYICON_VERSION; _NID.uID = 1; _iconStates = new Hashtable(); InitEventHandler(); }
private void UpdateIcon(bool forceDestroy = false) { if (DesignerProperties.GetIsInDesignMode(this)) return; var iconVisibility = IconVisibility; bool showIconInTray = !forceDestroy && (iconVisibility == NotifyIconVisibility.Visible || (iconVisibility == NotifyIconVisibility.UseControlVisibility && IsVisible)); lock (_syncObj) { IntPtr iconHandle = IntPtr.Zero; try { _allWindowsPermission.Demand(); if (showIconInTray && _hwndSource == null) { _hwndSource = new NotifyIconHwndSource(this); } if (_hwndSource != null) { _hwndSource.LockReference(showIconInTray); var pnid = new NativeMethods.NOTIFYICONDATA { uCallbackMessage = (int)NativeMethods.WindowMessage.TrayMouseMessage, uFlags = NativeMethods.NotifyIconFlags.Message | NativeMethods.NotifyIconFlags.ToolTip, hWnd = _hwndSource.Handle, uID = _id, szTip = Text }; if (Icon != null) { iconHandle = NativeMethods.GetHIcon(Icon); pnid.uFlags |= NativeMethods.NotifyIconFlags.Icon; pnid.hIcon = iconHandle; } if (showIconInTray && iconHandle != IntPtr.Zero) { if (!_iconCreated) { NativeMethods.Shell_NotifyIcon(0, pnid); _iconCreated = true; } else { NativeMethods.Shell_NotifyIcon(1, pnid); } } else if (_iconCreated) { NativeMethods.Shell_NotifyIcon(2, pnid); _iconCreated = false; } } } finally { if (iconHandle != IntPtr.Zero) { NativeMethods.DestroyIcon(iconHandle); } } } }
public void ShowBalloonTip(int timeout, string tipTitle, string tipText, NotifyBalloonIcon tipIcon) { if (timeout < 0) { throw new ArgumentOutOfRangeException("timeout", timeout, "Timeout cannot be negative."); } //ArgumentValidator.NotNullOrEmptyString(tipText, "tipText"); //ArgumentValidator.EnumValueIsDefined(typeof(NotifyBalloonIcon), tipIcon, "tipIcon"); if (_iconCreated) { _allWindowsPermission.Demand(); var pnid = new NativeMethods.NOTIFYICONDATA { hWnd = _hwndSource.Handle, uID = _id, uFlags = NativeMethods.NotifyIconFlags.Balloon, uTimeoutOrVersion = timeout, szInfoTitle = tipTitle, szInfo = tipText, dwInfoFlags = (int)tipIcon }; NativeMethods.Shell_NotifyIcon(1, pnid); } }
private void UpdateIcon(bool forceDestroy = false) { if (DesignerProperties.GetIsInDesignMode(this)) { return; } var iconVisibility = IconVisibility; bool showIconInTray = !forceDestroy && (iconVisibility == NotifyIconVisibility.Visible || (iconVisibility == NotifyIconVisibility.UseControlVisibility && IsVisible)); lock (_syncObj) { IntPtr iconHandle = IntPtr.Zero; try { _allWindowsPermission.Demand(); if (showIconInTray && _hwndSource == null) { _hwndSource = new NotifyIconHwndSource(this); } if (_hwndSource != null) { _hwndSource.LockReference(showIconInTray); var pnid = new NativeMethods.NOTIFYICONDATA { uCallbackMessage = (int)NativeMethods.WindowMessage.TrayMouseMessage, uFlags = NativeMethods.NotifyIconFlags.Message | NativeMethods.NotifyIconFlags.ToolTip, hWnd = _hwndSource.Handle, uID = _id, szTip = Text }; if (Icon != null) { iconHandle = NativeMethods.GetHIcon(Icon); pnid.uFlags |= NativeMethods.NotifyIconFlags.Icon; pnid.hIcon = iconHandle; } if (showIconInTray && iconHandle != IntPtr.Zero) { if (!_iconCreated) { NativeMethods.Shell_NotifyIcon(0, pnid); _iconCreated = true; } else { NativeMethods.Shell_NotifyIcon(1, pnid); } } else if (_iconCreated) { NativeMethods.Shell_NotifyIcon(2, pnid); _iconCreated = false; } } } finally { if (iconHandle != IntPtr.Zero) { NativeMethods.DestroyIcon(iconHandle); } } } }
private static bool UpdateIconData(Tuple <SystemTray.TrayIcon, PictureBox, ToolTip> prevIconData, NativeMethods.NOTIFYICONDATA iconData) { var pictureBox = prevIconData.Item2; var trayIcon = prevIconData.Item1; // updates the message callback if ((iconData.uFlags.HasFlag(NativeMethods.NIF.NIF_MESSAGE)) && iconData.uCallbackMessage != trayIcon.callbackMessage) { trayIcon.callbackMessage = iconData.uCallbackMessage; } // updates the message tip if ((iconData.uFlags.HasFlag(NativeMethods.NIF.NIF_TIP)) && iconData.szTip != trayIcon.tooltip) { trayIcon.tooltip = iconData.szTip; prevIconData.Item3.SetToolTip(pictureBox, trayIcon.tooltip); } // updates the icon if ((iconData.uFlags.HasFlag(NativeMethods.NIF.NIF_ICON)) && (IntPtr)iconData.hIcon != trayIcon.iconHandle && iconData.hIcon != 0) { trayIcon.iconHandle = (IntPtr)iconData.hIcon; SetPictureBoxIcon(pictureBox, trayIcon); } // updates the state if ((iconData.uFlags.HasFlag(NativeMethods.NIF.NIF_STATE)) && (iconData.dwState & iconData.dwStateMask) != trayIcon.state) { trayIcon.state = iconData.dwState & iconData.dwStateMask; return(true); } return(false); }
private static void TrayIconDeleted(NativeMethods.NOTIFYICONDATA iconData) { IconRemoved(Tuple.Create(iconData.hWnd, iconData.uID)); }
private static void TrayIconModified(NativeMethods.NOTIFYICONDATA iconData) { IconModified(iconData, Tuple.Create(iconData.hWnd, iconData.uID)); }