Beispiel #1
0
        protected override void WndProc(ref Message m)
        {
            Debugger.Log(1, "WindowsMessages", m.ToString() + "\n");

            switch (m.Msg)
            {
            case (int)WindowsMessages.WM_CREATE:
                // Retrieve any initialization data from the Regedit.ini file. Set a window timer for the screen saver window. Perform any other required initialization.
                InitGraphics();

                _context.Initialize(_isPreview);

                SetTimer(this.Handle, new IntPtr(1), 500, IntPtr.Zero);

                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_ERASEBKGND:
                // Erase the screen saver window and prepare for subsequent drawing operations.
                _windowGraphics.Clear(SystemColors.Desktop);

                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_TIMER:
                // Perform drawing operations.
                _context.Render(_windowGraphics, _clipBounds);

                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_DESTROY:
                // Destroy the timers created when the application processed the WM_CREATE message. Perform any additional required cleanup
                Dispose(true);

                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_ACTIVATE:
                // Terminate the screen saver if the wParam parameter is set to FALSE
                bool wParamBoolValue = Convert.ToBoolean(m.WParam.ToInt32());
                if (wParamBoolValue == false)
                {
                    Application.Exit();
                }
                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_SETCURSOR:
                // Set the cursor to the null cursor, removing it from the screen.
                SetCursor(IntPtr.Zero);

                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_PAINT:
                // Paint the screen background.
                _context.RenderBackground(_windowGraphics, _clipBounds);

                m.Result = IntPtr.Zero;
                break;

            case (int)WindowsMessages.WM_MOUSEMOVE:
                // Terminate the screen saver (if the mouse actually moved)
                if (!_isPreview)
                {
                    int lparamValue = m.LParam.ToInt32();
                    int loword      = lparamValue & 0x0000FFFF;
                    int hiword      = (int)((lparamValue & 0xFFFF0000) >> 16);

                    Point?p = new Point(loword, hiword);
                    if (_lastMousePosition == null)
                    {
                        _lastMousePosition = p;
                    }
                    else if (_lastMousePosition != p)
                    {
                        Application.Exit();
                    }
                    m.Result = IntPtr.Zero;
                }
                break;

            case (int)WindowsMessages.WM_LBUTTONDOWN:
            case (int)WindowsMessages.WM_RBUTTONDOWN:
            case (int)WindowsMessages.WM_MBUTTONDOWN:
            case (int)WindowsMessages.WM_KEYDOWN:
                // Terminate the screen saver.
                if (!_isPreview)
                {
                    Application.Exit();
                    m.Result = IntPtr.Zero;
                }
                break;

            default:
                break;
            }

            base.WndProc(ref m);
        }