Beispiel #1
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                window.SetWindowLong(0, IntPtr.Zero);     // on/off flag
                return(0);

            case MessageType.KeyDown:
                // Send most key presses to the parent window
                if ((VirtualKey)wParam != VirtualKey.Return && (VirtualKey)wParam != VirtualKey.Space)
                {
                    window.GetParent().SendMessage(message, wParam, lParam);
                    return(0);
                }

                // For Return and Space, fall through to toggle the square
                goto case MessageType.LeftButtonDown;

            case MessageType.LeftButtonDown:
                window.SetWindowLong(0, (IntPtr)(1 ^ (int)window.GetWindowLong(0)));
                window.SetFocus();
                window.Invalidate(false);
                return(0);

            // For focus messages, invalidate the window for repaint
            case MessageType.SetFocus:
                Checker4.idFocus = (int)window.GetWindowLong(WindowLong.Id);
                // Fall through
                goto case MessageType.KillFocus;

            case MessageType.KillFocus:
                window.Invalidate();
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    Rectangle rect = window.GetClientRectangle();
                    dc.Rectangle(rect);

                    if (window.GetWindowLong(0) != IntPtr.Zero)
                    {
                        dc.MoveTo(new Point(0, 0));
                        dc.LineTo(new Point(rect.Right, rect.Bottom));
                        dc.MoveTo(new Point(0, rect.Bottom));
                        dc.LineTo(new Point(rect.Right, 0));
                    }

                    // Draw the "focus" rectangle
                    if (window == Windows.GetFocus())
                    {
                        rect.Inflate(rect.Width / -10, rect.Height / -10);

                        dc.SelectObject(StockBrush.Null);
                        using PenHandle pen = Gdi.CreatePen(PenStyle.Dash, 0, default);
                        dc.SelectObject(pen);
                        dc.Rectangle(rect);
                        dc.SelectObject(StockPen.Black);
                    }
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Beispiel #2
0
        static LRESULT ChildWindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                window.SetWindowLong(0, IntPtr.Zero);     // on/off flag
                return(0);

            case WindowMessage.KeyDown:
                // Send most key presses to the parent window
                if ((VirtualKey)wParam != VirtualKey.Return && (VirtualKey)wParam != VirtualKey.Space)
                {
                    window.GetParent().SendMessage(message, wParam, lParam);
                    return(0);
                }

                // For Return and Space, fall through to toggle the square
                goto case WindowMessage.LeftButtonDown;

            case WindowMessage.LeftButtonDown:
                window.SetWindowLong(0, (IntPtr)(1 ^ (int)window.GetWindowLong(0)));
                window.SetFocus();
                window.Invalidate(false);
                return(0);

            // For focus messages, invalidate the window for repaint
            case WindowMessage.SetFocus:
                idFocus = (int)window.GetWindowLong(WindowLong.Id);
                // Fall through
                goto case WindowMessage.KillFocus;

            case WindowMessage.KillFocus:
                window.Invalidate();
                return(0);

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    RECT rect = window.GetClientRectangle();
                    dc.Rectangle(rect);

                    if (window.GetWindowLong(0) != IntPtr.Zero)
                    {
                        dc.MoveTo(0, 0);
                        dc.LineTo(rect.right, rect.bottom);
                        dc.MoveTo(0, rect.bottom);
                        dc.LineTo(rect.right, 0);
                    }

                    // Draw the "focus" rectangle
                    if (window == Windows.GetFocus())
                    {
                        rect.left   += rect.right / 10;
                        rect.right  -= rect.left;
                        rect.top    += rect.bottom / 10;
                        rect.bottom -= rect.top;
                        dc.SelectObject(StockBrush.Null);
                        using (PenHandle pen = Windows.CreatePen(PenStyle.Dash, 0, 0))
                        {
                            dc.SelectObject(pen);
                            dc.Rectangle(rect);
                            dc.SelectObject(StockPen.Black);
                        }
                    }
                }
                return(0);
            }
            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }