/// <summary> /// Update the tray icon with new data. /// </summary> /// <param name="icon">Type of icon to present.</param> /// <param name="iconTooltip">Icon tooltip text.</param> /// <param name="visible">Sets the visibility parameter of the tray icon.</param> public void UpdateIcon(IconType icon, string iconTooltip, bool visible = true) { var nIconData = new Windows.Shell32Structures.NotifyIconData { CallbackMessage = 2048, Flags = (int)Shell32.NotifyIconFlags.NifMessage | (int)Shell32.NotifyIconFlags.NifIcon | (int)Shell32.NotifyIconFlags.NifTip, Handle = hWnd, UId = uId, IconHandle = iconHandles[icon], Tip = iconTooltip, }; if (visible) { if (!addedToTray) { Shell32.ShellNotifyIcon(Shell32.NotifyIconMessage.NimAdd, nIconData); addedToTray = true; } else { Shell32.ShellNotifyIcon(Shell32.NotifyIconMessage.NimModify, nIconData); } } else { if (addedToTray) { Shell32.ShellNotifyIcon(Shell32.NotifyIconMessage.NimDelete, nIconData); addedToTray = false; } } }
/// <summary> /// Shows a balloon tip/toast in the system tray. /// </summary> /// <param name="timeout">Number of miliseconds after which the tip is hidden.</param> /// <param name="tipTitle">Title of the balloon/toast.</param> /// <param name="tipText">Contents of the balloon/toast.</param> /// <param name="icon">Icon accompanying the popup balloon/toast.</param> public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToastIconType icon) { var nIconData = new Windows.Shell32Structures.NotifyIconData { Handle = hWnd, UId = uId, Flags = (int)Shell32.NotifyIconFlags.NifInfo, Timeout = timeout, InfoTitle = tipTitle, Info = tipText, BalloonIconHandle = toastIconHandles[icon], InfoFlags = (int)Shell32.NotifyIconInfoFlags.NiifLargeIcon | (int)Shell32.NotifyIconInfoFlags.NiifUser | (int)Shell32.NotifyIconInfoFlags.NiifNoSound, }; Shell32.ShellNotifyIcon(Shell32.NotifyIconMessage.NimModify, nIconData); }