Пример #1
0
        private static bool HandleMouseEvent(NativeMouseEvent eventCode, MousePosition pos, int wheelDelta)
        {
            switch (eventCode)
            {
            case NativeMouseEvent.WM_MOUSEMOVE:
                OnMouseMove?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_LBUTTONDOWN:
                OnMouseLeftDown?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_LBUTTONUP:
                OnMouseLeftUp?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_RBUTTONDOWN:
                OnMouseRightDown?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_RBUTTONUP:
                OnMouseRightUp?.Invoke(pos);
                return(true);

            case NativeMouseEvent.WM_MOUSEWHEEL:
                OnMouseWheel?.Invoke(pos, wheelDelta);
                return(true);

            default:
                return(false);
            }
        }
Пример #2
0
        LRESULT WndProc(HWND hwnd, WM msg, WPARAM wParam, LPARAM lParam)
        {
            switch (msg)
            {
            case WM.CLOSE:
                OnClose?.Invoke();
                if (DestroyWhenClose == null || DestroyWhenClose())
                {
                    User32.DestroyWindow(hwnd);
                }
                return(0);

            case WM.ENABLE:
                OnEnable?.Invoke(wParam);
                break;

            case WM.SHOWWINDOW:
                OnShow?.Invoke(wParam);
                break;

            case WM.DESTROY:
                OnDestroy?.Invoke();
                return(0);

            case WM.MOUSEMOVE:
                OnMouseMove?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.LBUTTONDOWN:
                OnMouseLeftDown?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.LBUTTONUP:
                OnMouseLeftUp?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.LBUTTONDBLCLK:
                OnMouseLeftDoubleClicked?.Invoke();
                return(0);

            case WM.RBUTTONDOWN:
                OnMouseRightDown?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.RBUTTONUP:
                OnMouseRightUp?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.MBUTTONDOWN:
                OnMouseMiddleDown?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.MBUTTONUP:
                OnMouseMiddleUp?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.MOUSEWHEEL:
                OnMouseWheel?.Invoke(wParam.HiWord);
                return(0);

            case WM.RESIZE:
                OnResize?.Invoke(lParam.LowWord, lParam.HiWord);
                return(0);

            case WM.PAINT:
            {
                var ps = default(PAINTSTRUCT);
                User32.BeginPaint(hwnd, ref ps);
                OnPaint?.Invoke();
                User32.EndPaint(hwnd, ref ps);
            }
                return(0);
            }
            return(User32.DefWindowProcW(hwnd, msg, wParam, lParam));
        }