コード例 #1
0
        /// <summary>
        /// Processes incoming system messages.
        /// </summary>
        /// <param name="msg">Callback ID.</param>
        /// <param name="wParam">If the version is <see cref="NotifyIconVersion.Vista"/>
        /// or higher, this parameter can be used to resolve mouse coordinates.
        /// Currently not in use.</param>
        /// <param name="lParam">Provides information about the event.</param>
        private void ProcessWindowMessage(uint msg, IntPtr wParam, IntPtr lParam)
        {
            if (msg != CallbackMessageId)
            {
                return;
            }

            var message = (WindowsMessages)lParam.ToInt32();

            switch (message)
            {
            case WindowsMessages.WM_CONTEXTMENU:
                // TODO: Handle WM_CONTEXTMENU, see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
                Debug.WriteLine("Unhandled WM_CONTEXTMENU");
                break;

            case WindowsMessages.WM_MOUSEMOVE:
                MouseEventReceived?.Invoke(MouseEvent.MouseMove);
                break;

            case WindowsMessages.WM_LBUTTONDOWN:
                MouseEventReceived?.Invoke(MouseEvent.IconLeftMouseDown);
                break;

            case WindowsMessages.WM_LBUTTONUP:
                if (!isDoubleClick)
                {
                    MouseEventReceived?.Invoke(MouseEvent.IconLeftMouseUp);
                }
                isDoubleClick = false;
                break;

            case WindowsMessages.WM_LBUTTONDBLCLK:
                isDoubleClick = true;
                MouseEventReceived?.Invoke(MouseEvent.IconDoubleClick);
                break;

            case WindowsMessages.WM_RBUTTONDOWN:
                MouseEventReceived?.Invoke(MouseEvent.IconRightMouseDown);
                break;

            case WindowsMessages.WM_RBUTTONUP:
                MouseEventReceived?.Invoke(MouseEvent.IconRightMouseUp);
                break;

            case WindowsMessages.WM_RBUTTONDBLCLK:
                //double click with right mouse button - do not trigger event
                break;

            case WindowsMessages.WM_MBUTTONDOWN:
                MouseEventReceived?.Invoke(MouseEvent.IconMiddleMouseDown);
                break;

            case WindowsMessages.WM_MBUTTONUP:
                MouseEventReceived?.Invoke(MouseEvent.IconMiddleMouseUp);
                break;

            case WindowsMessages.WM_MBUTTONDBLCLK:
                //double click with middle mouse button - do not trigger event
                break;

            case WindowsMessages.NIN_BALLOONSHOW:
                BalloonToolTipChanged?.Invoke(true);
                break;

            case WindowsMessages.NIN_BALLOONHIDE:
            case WindowsMessages.NIN_BALLOONTIMEOUT:
                BalloonToolTipChanged?.Invoke(false);
                break;

            case WindowsMessages.NIN_BALLOONUSERCLICK:
                MouseEventReceived?.Invoke(MouseEvent.BalloonToolTipClicked);
                break;

            case WindowsMessages.NIN_POPUPOPEN:
                ChangeToolTipStateRequest?.Invoke(true);
                break;

            case WindowsMessages.NIN_POPUPCLOSE:
                ChangeToolTipStateRequest?.Invoke(false);
                break;

            case WindowsMessages.NIN_SELECT:
                // TODO: Handle NIN_SELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
                Debug.WriteLine("Unhandled NIN_SELECT");
                break;

            case WindowsMessages.NIN_KEYSELECT:
                // TODO: Handle NIN_KEYSELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
                Debug.WriteLine("Unhandled NIN_KEYSELECT");
                break;

            default:
                Debug.WriteLine("Unhandled NotifyIcon message ID: " + lParam);
                break;
            }
        }
コード例 #2
0
        /// <summary>Handle windows messages for the notification icon</summary>
        private void ProcessWindowMessage(int msg, IntPtr wParam, IntPtr lParam)
        {
            if (msg != CallbackMessageId)
            {
                return;
            }

            var message = lParam.ToInt32();

            switch (message)
            {
            case Win32.WM_CONTEXTMENU:
            {
                // TODO: Handle WM_CONTEXTMENU, see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
                //Debug.WriteLine("Unhandled WM_CONTEXTMENU");
                break;
            }

            case Win32.NIN_BALLOONSHOW:
            {
                BalloonToolTipChanged?.Invoke(true);
                break;
            }

            case Win32.NIN_BALLOONHIDE:
            case Win32.NIN_BALLOONTIMEOUT:
            {
                BalloonToolTipChanged?.Invoke(false);
                break;
            }

            case Win32.NIN_BALLOONUSERCLICK:
            {
                //MouseEventReceived?.Invoke(MouseEvent.BalloonToolTipClicked);
                break;
            }

            case Win32.NIN_POPUPOPEN:
            {
                ChangeToolTipStateRequest?.Invoke(true);
                break;
            }

            case Win32.NIN_POPUPCLOSE:
            {
                ChangeToolTipStateRequest?.Invoke(false);
                break;
            }

            case Win32.NIN_SELECT:
            {
                // TODO: Handle NIN_SELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
                //Debug.WriteLine("Unhandled NIN_SELECT");
                break;
            }

            case Win32.NIN_KEYSELECT:
            {
                // TODO: Handle NIN_KEYSELECT see https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shell_notifyiconw
                //Debug.WriteLine("Unhandled NIN_KEYSELECT");
                break;
            }

            case Win32.WM_MOUSEMOVE:
            {
                MouseMove?.Invoke(this, new MouseEventArgs(Mouse.PrimaryDevice, Win32.GetMessageTime()));
                break;
            }

            case Win32.WM_LBUTTONDOWN:
            case Win32.WM_LBUTTONUP:
            case Win32.WM_LBUTTONDBLCLK:
            {
                MouseButton?.Invoke(this, new MouseButtonEventArgs(Mouse.PrimaryDevice, Win32.GetMessageTime(), System.Windows.Input.MouseButton.Left));
                break;
            }

            case Win32.WM_RBUTTONDOWN:
            case Win32.WM_RBUTTONUP:
            case Win32.WM_RBUTTONDBLCLK:
            {
                MouseButton?.Invoke(this, new MouseButtonEventArgs(Mouse.PrimaryDevice, Win32.GetMessageTime(), System.Windows.Input.MouseButton.Right));
                break;
            }

            case Win32.WM_MBUTTONDOWN:
            case Win32.WM_MBUTTONUP:
            case Win32.WM_MBUTTONDBLCLK:
            {
                MouseButton?.Invoke(this, new MouseButtonEventArgs(Mouse.PrimaryDevice, Win32.GetMessageTime(), System.Windows.Input.MouseButton.Middle));
                break;
            }

            case Win32.WM_MOUSEWHEEL:
            {
                MouseWheel?.Invoke(this, new MouseWheelEventArgs(Mouse.PrimaryDevice, Win32.GetMessageTime(), new Win32.WheelState(wParam).Delta));
                break;
            }

            default:
            {
                //Debug.WriteLine("Unhandled NotifyIcon message ID: " + lParam);
                break;
            }
            }
        }