Ejemplo n.º 1
0
        private IntPtr WindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
                #region keyboard
            case 0x100:    /*WM_KEYDOWN*/
            {
                var keyCode = wParam.ToInt32();
                if (wParam.ToInt64() < 256)
                {
                    Keyboard.Instance.lastKeyStates[keyCode] = Keyboard.Instance.keyStates[keyCode];
                    Keyboard.Instance.keyStates[keyCode]     = KeyState.Down;
                }

                if (keyCode == (int)Key.Enter)
                {
                    Ime.ImeBuffer.Enqueue('\n');
                    return(new IntPtr(1));
                }

                //DEBUG only begin
                if (keyCode == (int)Key.Escape)
                {
                    Application.Quit();
                }
                //DEBUG only end

                return(IntPtr.Zero);
            }

            case 0x101:    /*WM_KEYUP*/
            {
                var keyCode = wParam.ToInt32();
                if (wParam.ToInt64() < 256)
                {
                    Keyboard.Instance.lastKeyStates[keyCode] = Keyboard.Instance.keyStates[keyCode];
                    Keyboard.Instance.keyStates[keyCode]     = KeyState.Up;
                }
                return(IntPtr.Zero);
            }

                #endregion
                #region mouse
            case 0x0020:     //WM_SETCURSOR
            {
                if (wParam == hWnd)
                {
                    //HTCLIENT is 1, see https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-nchittest#return-value
                    if (unchecked ((short)lParam) == 1 /*HTCLIENT*/)
                    {
                        Win32Cursor.ChangeCursor(Mouse.Instance.Cursor);
                        return(TRUE);
                    }
                }
                break;
            }

            case 0x0201:    //WM_LBUTTONDOWN
                Mouse.Instance.LeftButtonState = KeyState.Down;
                return(IntPtr.Zero);

            case 0x0202:    //WM_LBUTTONUP
                Mouse.Instance.LeftButtonState = KeyState.Up;
                return(IntPtr.Zero);

            case 0x0203:    //WM_LBUTTONDBLCLK
                return(IntPtr.Zero);

            case 0x0206:    //WM_RBUTTONDBLCLK
                return(IntPtr.Zero);

            case 0x0204:    //WM_RBUTTONDOWN
                Mouse.Instance.RightButtonState = KeyState.Down;
                return(IntPtr.Zero);

            case 0x0205:    //WM_RBUTTONUP
                Mouse.Instance.RightButtonState = KeyState.Up;
                return(IntPtr.Zero);

            case 0x020A:    //WM_MOUSEWHEEL
                Mouse.Instance.MouseWheel = ((short)(wParam.ToInt64() >> 16));
                return(IntPtr.Zero);

            case 0x0200:    //WM_MOUSEMOVE
                var p = new POINT
                {
                    X = unchecked ((short)lParam),
                    Y = unchecked ((short)((uint)lParam >> 16))
                };
                Mouse.Instance.Position = new Point(p.X, p.Y);
                return(IntPtr.Zero);

                #endregion
                #region ime
            //http://blog.csdn.net/shuilan0066/article/details/7679825
            case 0x0286:    /*WM_IME_CHAR*/
            {
                char c = (char)wParam;
                if (c > 0 && !char.IsControl(c))
                {
                    Ime.ImeBuffer.Enqueue(c);
                }
                return(IntPtr.Zero);
            }

            case 0x0102:    /*WM_CHAR*/
            {
                char c = (char)wParam;
                if (c > 0 && !char.IsControl(c))
                {
                    Ime.ImeBuffer.Enqueue(c);
                }
                return(IntPtr.Zero);
            }

                #endregion
            case 0x2:    //WM_DESTROY
                Close();
                return(IntPtr.Zero);
            }
            return(DefWindowProc(hWnd, msg, wParam, lParam));
        }
Ejemplo n.º 2
0
 private static void DoChangeCursor(Cursor cursor)
 {
     Win32Cursor.ChangeCursor(cursor);
 }