public void Recreate()
 {
     if (this.IsVisible)
     {
         this.notifyIconId = NotifyIconInteropHelper.CreateNotifyIcon(this.callback, this.icon);
     }
 }
 public void SetFocus()
 {
     if (this.IsVisible)
     {
         NotifyIconInteropHelper.SetFocusToNotifyIcon(this.notifyIconId.Value);
     }
 }
Exemplo n.º 3
0
        public static void SetFocusToNotifyIcon(int iconId)
        {
            NotifyIconData IconData = new NotifyIconData {
                cbSize = Marshal.SizeOf(typeof(NotifyIconData))
            };

            IconData.hwnd = NotifyIconInteropHelper.HookWindow.Handle;
            IconData.uID  = iconId;

            NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.SetFocus, ref IconData);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        public static int CreateNotifyIcon(INotifyIconCallback messageCallback, Bitmap icon)
        {
            int Id = NotifyIconInteropHelper.nextNotifyIconId++;

            NotifyIconInteropHelper.HookWindow.AddMessageHook(Id, messageCallback);
            NotifyIconInteropHelper.iconHandles.Add(Id, icon.GetHicon());

            NotifyIconData IconData = new NotifyIconData {
                cbSize = Marshal.SizeOf(typeof(NotifyIconData))
            };

            IconData.hwnd             = NotifyIconInteropHelper.HookWindow.Handle;
            IconData.uID              = Id;
            IconData.uFlags           = 0x00000003; // NIF_Message (1), NIF_ICON (2)
            IconData.uCallbackMessage = (int)Win32.Wm.App;
            IconData.hIcon            = NotifyIconInteropHelper.iconHandles[Id];
            IconData.uVersion         = 3; //Window 2000 and later (4 would be Vista and later). Changes message handling!

            NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.Add, ref IconData);
            NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.SetVersion, ref IconData);

            return(Id);
        }