public static void DeleteNotifyIcon(int iconId) { NotifyIconInteropHelper.DestroyIcon(NotifyIconInteropHelper.iconHandles[iconId]); NotifyIconInteropHelper.iconHandles.Remove(iconId); NotifyIconData IconData = new NotifyIconData { cbSize = Marshal.SizeOf(typeof(NotifyIconData)) }; IconData.hwnd = NotifyIconInteropHelper.HookWindow.Handle; IconData.uID = iconId; NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.Delete, ref IconData); NotifyIconInteropHelper.HookWindow.RemoveMessageHook(iconId); }
public static void ChangeNotifyIcon(int iconId, Bitmap icon) { NotifyIconInteropHelper.DestroyIcon(NotifyIconInteropHelper.iconHandles[iconId]); NotifyIconInteropHelper.iconHandles[iconId] = icon.GetHicon(); NotifyIconData IconData = new NotifyIconData { cbSize = Marshal.SizeOf(typeof(NotifyIconData)) }; IconData.hwnd = NotifyIconInteropHelper.HookWindow.Handle; IconData.uID = iconId; IconData.uFlags = 0x00000002; // NIF_ICON (2) IconData.hIcon = NotifyIconInteropHelper.iconHandles[iconId]; NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.Modify, ref IconData); }