Exemple #1
0
        private static IntPtr WindowProc(IntPtr hwnd, uint umsg,
                                         IntPtr wParam, IntPtr lParam)
        {
            var msg = (WM)umsg;

            switch (msg)
            {
            case WM.ERASEBKGND:
                return(new IntPtr(1));

            case WM.CLOSE:
            {
                User32Methods.PostQuitMessage(0);
                break;
            }

            case WM.PAINT:
            {
                PaintStruct ps;
                var         hdc = User32Methods.BeginPaint(hwnd, out ps);
                User32Methods.FillRect(hdc, ref ps.PaintRect,
                                       Gdi32Helpers.GetStockObject(StockObject.WHITE_BRUSH));
                User32Methods.EndPaint(hwnd, ref ps);
                break;
            }
            }
            return(User32Methods.DefWindowProc(hwnd, umsg, wParam, lParam));
        }
Exemple #2
0
        protected override void OnPaint(ref PaintPacket packet)
        {
            PaintStruct ps;
            var         hdc = this.BeginPaint(out ps);

            User32Methods.FillRect(hdc, ref ps.PaintRect,
                                   Gdi32Helpers.GetStockObject(StockObject.WHITE_BRUSH));
            this.EndPaint(ref ps);
            base.OnPaint(ref packet);
        }
Exemple #3
0
 static int Main(string[] args)
 {
     try
     {
         ApplicationHelpers.SetupDefaultExceptionHandlers();
         Gl.Initialize();
         var factory = WindowFactory.Create(hBgBrush: Gdi32Helpers.GetStockObject(StockObject.BLACK_BRUSH));
         using (var win = Window.Create <AppWindow>(factory: factory, text: "Hello"))
         {
             win.Show();
             return(new EventLoop().Run(win));
         }
     }
     catch (Exception ex)
     {
         MessageBoxHelpers.ShowError(ex);
         return(1);
     }
 }
Exemple #4
0
        private static IntPtr WindowProc(IntPtr hwnd, uint umsg, IntPtr wParam, IntPtr lParam)
        {
            IntPtr result = IntPtr.Zero;

            var msg = (WM)umsg;

            switch (msg)
            {
            case WM.ERASEBKGND:
                return(new IntPtr(1));

            case WM.CLOSE: User32Methods.PostQuitMessage(0);
                break;

            case WM.PAINT:
            {
                var hdc = User32Methods.BeginPaint(hwnd, out PaintStruct ps);
                User32Methods.FillRect(hdc, ref ps.PaintRect,
                                       Gdi32Helpers.GetStockObject(StockObject.WHITE_BRUSH));
                User32Methods.EndPaint(hwnd, ref ps);
                break;
            }

            case WM.KEYDOWN: InputManager.Instance.KeyPressed((VirtualKey)wParam.ToInt32(), lParam.ToInt32() & 0x40000000);
                break;

            case WM.KEYUP: InputManager.Instance.KeyReleased((VirtualKey)wParam.ToInt32());
                break;

            case WM.CHAR: InputManager.Instance.KeyTyped((char)wParam.ToInt32());
                break;

            case WM.MOUSEMOVE:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MouseMoved(x, y);
                break;
            }

            case WM.LBUTTONDOWN:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MousePressed(MouseButton.Left, x, y);
                break;
            }

            case WM.LBUTTONUP:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MouseReleased(MouseButton.Left, x, y);
                break;
            }

            case WM.RBUTTONDOWN:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MousePressed(MouseButton.Right, x, y);
                break;
            }

            case WM.RBUTTONUP:
            {
                int x = unchecked ((short)(long)lParam);
                int y = unchecked ((short)((long)lParam >> 16));
                InputManager.Instance.MouseReleased(MouseButton.Right, x, y);
                break;
            }

            default:
                result = User32Methods.DefWindowProc(hwnd, umsg, wParam, lParam);
                break;
            }
            return(result);
        }