Esempio n. 1
0
        private bool HandleWindowEvent(IntPtr hwnd, Win32MessageType uMsg, IntPtr wParam, IntPtr lParam)
        {
            if (!windows.TryGetValue(hwnd, out var window))
            {
                return(false);
            }

            uint wParam32 = (uint)wParam.ToInt64();
            uint lParam32 = (uint)lParam.ToInt64();

            return(Win32EventHandler.HandleWindowEvent(window, uMsg, wParam32, lParam32));
        }
Esempio n. 2
0
        private static void HandleActivate(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
        {
            bool activated = (wParam & 0xFFFF) != 0;

            if (activated)
            {
                window.StartupInfo.OnActivated();
            }
            else
            {
                window.StartupInfo.OnDeactivated();
            }
        }
Esempio n. 3
0
        public static bool HandleWindowEvent(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
        {
            int messageTypeIndex = (int)messageType;

            if (messageTypeIndex < 0 || messageTypeIndex >= eventHandlers.Length)
            {
                return(false);
            }

            HandleWin32Event eventHandler = eventHandlers[messageTypeIndex];

            if (eventHandler == null)
            {
                return(false);
            }

            eventHandler(window, messageType, wParam, lParam);
            return(true);
        }
Esempio n. 4
0
 public static extern LRESULT DefWindowProcW(
     HWND hWnd,
     Win32MessageType uMsg,
     WPARAM wParam,
     LPARAM lParam
     );
Esempio n. 5
0
        private IntPtr WindowProc(IntPtr hwnd, Win32MessageType uMsg, IntPtr wParam, IntPtr lParam)
        {
            if (HandleWindowEvent(hwnd, uMsg, wParam, lParam))
            {
                return(IntPtr.Zero);
            }

            if (uMsg == Win32MessageType.WM_SETCURSOR)
            {
                uint lParam32 = (uint)lParam.ToInt64();
                var  hitTest  = (Win32HitTestResult)(lParam32 & 0xFFFF);
                if (hitTest == Win32HitTestResult.HTCLIENT)
                {
                    IntPtr cursor = Win32API.LoadImageW(
                        IntPtr.Zero,
                        Win32SystemResources.IDC_ARROW,
                        Win32ImageType.IMAGE_CURSOR,
                        0, 0,
                        Win32LoadImageFlags.LR_DEFAULTSIZE | Win32LoadImageFlags.LR_SHARED
                        );
                    if (cursor != IntPtr.Zero)
                    {
                        Win32API.SetCursor(cursor);
                        return(IntPtr.Zero);
                    }
                }
            }

            if (uMsg == Win32MessageType.WM_DESTROY)
            {
                windows.Remove(hwnd);
                Win32API.PostQuitMessage(0);
                return(IntPtr.Zero);
            }

            if (uMsg == Win32MessageType.WM_MOUSEMOVE)
            {
                if (windows.TryGetValue(hwnd, out var window))
                {
                    uint wParam32 = (uint)wParam.ToInt64();
                    uint lParam32 = (uint)lParam.ToInt64();
                    int  x        = (short)(lParam32 & 0xFFFF);
                    int  y        = (short)((lParam32 >> 16) & 0xFFFF);
                    window.StartupInfo.OnMouseMove(new Point(x, y));
                }

                return(IntPtr.Zero);
            }

            if (uMsg == Win32MessageType.WM_CHAR)
            {
                if (windows.TryGetValue(hwnd, out var window))
                {
                    char c = (char)wParam.ToInt64();

                    if (!char.IsControl(c))
                    {
                        window.StartupInfo.OnTextInput(c.ToString());
                    }
                }

                return(IntPtr.Zero);
            }

            if (uMsg == Win32MessageType.WM_PAINT)
            {
                PAINTSTRUCT ps  = new PAINTSTRUCT();
                IntPtr      hdc = Win32API.BeginPaint(hwnd, ref ps);
                try
                {
                    if (windows.TryGetValue(hwnd, out var window))
                    {
                        Rectangle area = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.Width, ps.rcPaint.Height);
                        using (Win32Bitmap bitmap = Win32Bitmap.Create(hdc, area.Width, area.Height))
                        {
                            using (Win32Canvas canvas = graphics.CreateCanvas(bitmap, new Point(-area.X, -area.Y)))
                            {
                                window.StartupInfo.OnPaint(canvas, area);
                            }

                            bitmap.CopyTo(hdc, area.X, area.Y);
                        }
                    }
                }
                finally
                {
                    Win32API.EndPaint(hwnd, ref ps);
                }

                return(IntPtr.Zero);
            }

            if (uMsg == Win32MessageType.WM_SIZE)
            {
                if (windows.TryGetValue(hwnd, out var window))
                {
                    ulong lParam32 = (uint)lParam.ToInt64();
                    int   width    = (short)(lParam32 & 0xFFFF);
                    int   height   = (short)((lParam32 >> 16) & 0xFFFF);
                    window.StartupInfo.OnResize(new Size(width, height));
                }

                return(IntPtr.Zero);
            }

            return(Win32API.DefWindowProcW(hwnd, uMsg, wParam, lParam));
        }
Esempio n. 6
0
        private static void HandleMouseButtonDown(NMouseButton mouseButton, Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
        {
            int x = (short)(lParam & 0xFFFF);
            int y = (short)((lParam >> 16) & 0xFFFF);

            Win32API.SetCapture(window.WindowHandle);

            window.StartupInfo.OnMouseButtonDown(mouseButton, new Point(x, y), GetModifierKey());
        }
Esempio n. 7
0
 private static void HandleXMouseButtonDown(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
 {
     HandleMouseButtonDown(GetXMouseButton(wParam), window, messageType, wParam, lParam);
 }
Esempio n. 8
0
 private static void HandleRightMouseButtonDown(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
 {
     HandleMouseButtonDown(NMouseButton.Right, window, messageType, wParam, lParam);
 }
Esempio n. 9
0
 private static void HandleKeyUp(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
 {
     window.StartupInfo.OnKeyUp(Win32KeyMap.GetKeyCode(lParam, wParam));
 }
Esempio n. 10
0
        private static void HandleKeyDown(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
        {
            bool autoRepeat = (lParam & 0x40000000) != 0;

            window.StartupInfo.OnKeyDown(Win32KeyMap.GetKeyCode(lParam, wParam), GetModifierKey(), autoRepeat);
        }
Esempio n. 11
0
        private static void HandleMouseButtonUp(NMouseButton mouseButton, Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
        {
            int x = (short)(lParam & 0xFFFF);
            int y = (short)((lParam >> 16) & 0xFFFF);

            if (!AnyMouseButtonIsDown())
            {
                Win32API.ReleaseCapture();
            }

            window.StartupInfo.OnMouseButtonUp(mouseButton, new Point(x, y));
        }
Esempio n. 12
0
 private static void HandleMiddleMouseButtonUp(Win32Window window, Win32MessageType messageType, uint wParam, uint lParam)
 {
     HandleMouseButtonUp(NMouseButton.Middle, window, messageType, wParam, lParam);
 }