Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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);
        }