Exemplo n.º 1
0
        static LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.Rectangle(Rectangle.FromLTRB(cxClient / 8, cyClient / 8, 7 * cxClient / 8, 7 * cyClient / 8));
                    dc.MoveTo(new Point(0, 0));
                    dc.LineTo(new Point(cxClient, cyClient));
                    dc.MoveTo(new Point(0, cyClient));
                    dc.LineTo(new Point(cxClient, 0));
                    dc.Ellipse(Rectangle.FromLTRB(cxClient / 8, cyClient / 8, 7 * cxClient / 8, 7 * cyClient / 8));
                    dc.RoundRectangle(
                        Rectangle.FromLTRB(cxClient / 4, cyClient / 4, 3 * cxClient / 4, 3 * cyClient / 4),
                        new Size(cxClient / 4, cyClient / 4));
                }
                return(0);

            case MessageType.Destroy:
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 2
0
        protected override void WndProc(ref Message m)
        {
            const Int32 HTCAPTION        = 0x00000002;
            const Int32 MF_BYCOMMAND     = 0x00000000;
            const Int32 MF_GRAYED        = 0x00000001;
            const Int32 MF_DISABLED      = 0x00000002;
            const Int32 SC_MOVE          = 0xF010;
            const Int32 WM_NCLBUTTONDOWN = 0xA1;
            const Int32 WM_SYSCOMMAND    = 0x112;
            const Int32 WM_INITMENUPOPUP = 0x117;

            switch (m.Msg)
            {
            case WM_INITMENUPOPUP:
            {
                if (m.LParam.ToInt32() / 65536 != 0)     // 'divide by 65536 to get hiword
                {
                    EnableMenuItem(m.WParam, SC_MOVE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
                }

                break;
            }

            //cancels the drag this is IMP
            case WM_NCLBUTTONDOWN when m.WParam.ToInt32() == HTCAPTION:

            // Cancels any clicks on move menu
            case WM_SYSCOMMAND when(m.WParam.ToInt32()& 0xFFF0) == SC_MOVE:
                return;
            }

            base.WndProc(ref m);
        }
Exemplo n.º 3
0
        static LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                Multimedia.PlaySound(PlaySoundAlias.SystemHand, PlaySoundOptions.Async | PlaySoundOptions.NoDefault);
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.DrawText(
                        "Hello, Windows 98!",
                        window.GetClientRectangle(),
                        TextFormat.SingleLine | TextFormat.Center | TextFormat.VerticallyCenter);
                }
                return(0);

            case MessageType.Destroy:
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets a hash code for the message.
        /// </summary>
        /// <returns>Hash code for this message.</returns>
        public override int GetHashCode()
        {
            int hash = WindowHandle.GetHashCode();

            hash = hash * 31 + Msg.GetHashCode();
            hash = hash * 31 + WParam.GetHashCode();
            hash = hash * 31 + LParam.GetHashCode();
            hash = hash * 31 + Time.GetHashCode();
            hash = hash * 31 + Point.GetHashCode();
            return(hash);
        }
Exemplo n.º 5
0
        LResult ListBoxProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            if (message == MessageType.KeyDown && (VirtualKey)wParam == VirtualKey.Return)
            {
                window.GetParent().SendMessage(
                    MessageType.Command,
                    new WParam(1, (ushort)ListBoxNotification.DoubleClick),
                    (LParam)window);
            }

            return(Windows.CallWindowProcedure(_existingListBoxWndProc, window, message, wParam, lParam));
        }
Exemplo n.º 6
0
        bool OnWM_MESSAGE256(ref System.Windows.Interop.MSG msg, ref bool handled)
        {
            // // add extra variables to observe with Debugger //
            IntPtr HWND, WParam, LParam;

            HWND                  = msg.hwnd;
            WParam                = msg.wParam;
            LParam                = msg.lParam;
            this.txt_HWND.Text    = HWND.ToString();
            this.txt_WParam.Text  = WParam.ToString();
            this.txt_LParam.Text  = LParam.ToString();
            this.txt_KeyData.Text = KeyInterop.KeyFromVirtualKey(WParam.ToInt32()).ToString();//keyData.ToString();

            return(true);
        }
Exemplo n.º 7
0
        static LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

            case MessageType.Destroy:
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 8
0
        private LResult ScrollProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            int id = (int)window.GetWindowLong(WindowLong.Id).ToInt64();

            switch (message)
            {
            case MessageType.KeyDown:
                if ((VirtualKey)wParam == VirtualKey.Tab)
                {
                    window.GetParent().GetDialogItem(
                        (id + ((Windows.GetKeyState(VirtualKey.Shift) & KeyState.Down) != 0 ? 2 : 1) % 3))
                    .SetFocus();
                }
                break;

            case MessageType.SetFocus:
                idFocus = id;
                break;
            }

            return(Windows.CallWindowProcedure(OldScroll[id], window, message, wParam, lParam));
        }
Exemplo n.º 9
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                // Create the white-rectangle window against which the
                // scroll bars will be positioned. The child window ID is 9.

                hwndRect = Windows.CreateWindow(
                    className: "static",
                    style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.WhiteRectangle,
                    parentWindow: window,
                    menuHandle: (MenuHandle)9,
                    instance: ModuleInstance);

                for (int i = 0; i < 3; i++)
                {
                    // The three scroll bars have IDs 0, 1, and 2, with
                    // scroll bar ranges from 0 through 255.
                    hwndScroll[i] = Windows.CreateWindow(
                        className: "scrollbar",
                        style: WindowStyles.Child | WindowStyles.Visible | WindowStyles.TabStop | (WindowStyles)ScrollBarStyles.Veritcal,
                        parentWindow: window,
                        menuHandle: (MenuHandle)i,
                        instance: ModuleInstance);

                    hwndScroll[i].SetScrollRange(ScrollBar.Control, 0, 255, false);
                    hwndScroll[i].SetScrollPosition(ScrollBar.Control, 0, false);

                    // The three color-name labels have IDs 3, 4, and 5,
                    // and text strings “Red”, “Green”, and “Blue”.
                    hwndLabel[i] = Windows.CreateWindow(
                        className: "static",
                        windowName: szColorLabel[i],
                        style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Center,
                        parentWindow: window,
                        menuHandle: (MenuHandle)(i + 3),
                        instance: ModuleInstance);

                    // The three color-value text fields have IDs 6, 7,
                    // and 8, and initial text strings of “0”.
                    hwndValue[i] = Windows.CreateWindow(
                        className: "static",
                        windowName: "0",
                        style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Center,
                        parentWindow: window,
                        menuHandle: (MenuHandle)(i + 6),
                        instance: ModuleInstance);

                    OldScroll[i] = hwndScroll[i].SetWindowProcedure(_scrollProcedure = ScrollProcedure);

                    hBrush[i] = Gdi.CreateSolidBrush(crPrim[i]);
                }

                hBrushStatic = Gdi.GetSystemColorBrush(SystemColor.ButtonHighlight);
                cyChar       = Windows.GetDialogBaseUnits().Height;

                return(0);

            case MessageType.Size:
                int cxClient = lParam.LowWord;
                int cyClient = lParam.HighWord;
                rcColor = Rectangle.FromLTRB(cxClient / 2, 0, cxClient, cyClient);
                hwndRect.MoveWindow(new Rectangle(0, 0, cxClient / 2, cyClient), repaint: true);

                for (int i = 0; i < 3; i++)
                {
                    hwndScroll[i].MoveWindow(
                        new Rectangle((2 * i + 1) * cxClient / 14, 2 * cyChar, cxClient / 14, cyClient - 4 * cyChar),
                        repaint: true);
                    hwndLabel[i].MoveWindow(
                        new Rectangle((4 * i + 1) * cxClient / 28, cyChar / 2, cxClient / 7, cyChar),
                        repaint: true);
                    hwndValue[i].MoveWindow(
                        new Rectangle((4 * i + 1) * cxClient / 28, cyClient - 3 * cyChar / 2, cxClient / 7, cyChar),
                        repaint: true);
                }

                window.SetFocus();
                return(0);

            case MessageType.SetFocus:
                hwndScroll[idFocus].SetFocus();
                return(0);

            case MessageType.VerticalScroll:
                int id = (int)((WindowHandle)lParam).GetWindowLong(WindowLong.Id);

                switch ((ScrollCommand)wParam.LowWord)
                {
                case ScrollCommand.PageDown:
                    color[id] += 15;
                    goto case ScrollCommand.LineDown;

                case ScrollCommand.LineDown:
                    color[id] = Math.Min(255, color[id] + 1);
                    break;

                case ScrollCommand.PageUp:
                    color[id] -= 15;
                    goto case ScrollCommand.LineUp;

                case ScrollCommand.LineUp:
                    color[id] = Math.Max(0, color[id] - 1);
                    break;

                case ScrollCommand.Top:
                    color[id] = 0;
                    break;

                case ScrollCommand.Bottom:
                    color[id] = 255;
                    break;

                case ScrollCommand.ThumbPosition:
                case ScrollCommand.ThumbTrack:
                    color[id] = wParam.HighWord;
                    break;

                default:
                    return(0);
                }

                hwndScroll[id].SetScrollPosition(ScrollBar.Control, color[id], true);

                hwndValue[id].SetWindowText(color[id].ToString());

                // We'll dispose when we set the next brush
                BrushHandle brush = Gdi.CreateSolidBrush(Color.FromArgb(color[0], color[1], color[2]));

                window.SetClassBackgroundBrush(brush).Dispose();
                window.InvalidateRectangle(rcColor, true);
                return(0);

            case MessageType.ControlColorScrollBar:
                return((BrushHandle)hBrush[(int)((WindowHandle)lParam).GetWindowLong(WindowLong.Id)]);

            case MessageType.ControlColorStatic:
                id = (int)((WindowHandle)lParam).GetWindowLong(WindowLong.Id);

                if (id >= 3 && id <= 8)
                {
                    DeviceContext dc = (DeviceContext)wParam;
                    dc.SetTextColor(crPrim[id % 3]);
                    dc.SetBackgroundColor(Windows.GetSystemColor(SystemColor.ButtonHighlight));
                    return((BrushHandle)hBrushStatic);
                }
                break;

            case MessageType.SystemColorChange:
                hBrushStatic = Gdi.GetSystemColorBrush(SystemColor.ButtonHighlight);
                return(0);

            case MessageType.Destroy:
                window.SetClassBackgroundBrush(StockBrush.White).Dispose();

                for (int i = 0; i < 3; i++)
                {
                    hBrush[i].Dispose();
                }

                break;
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 10
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.KeyDown:
                switch ((VirtualKey)wParam)
                {
                case VirtualKey.Home:
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.Top, 0);
                    break;

                case VirtualKey.End:
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.Bottom, 0);
                    break;

                case VirtualKey.Prior:
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.PageUp, 0);
                    break;

                case VirtualKey.Next:
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.PageDown, 0);
                    break;

                case VirtualKey.Up:
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.LineUp, 0);
                    break;

                case VirtualKey.Down:
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.LineDown, 0);
                    break;

                case VirtualKey.Left:
                    window.SendMessage(MessageType.HorizontalScroll, (uint)ScrollCommand.PageUp, 0);
                    break;

                case VirtualKey.Right:
                    window.SendMessage(MessageType.HorizontalScroll, (uint)ScrollCommand.PageDown, 0);
                    break;
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 11
0
 static LResult CallDefaultProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
 {
     return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
 }
Exemplo n.º 12
0
 // Token: 0x06000045 RID: 69 RVA: 0x00002830 File Offset: 0x00001830
 public override string ToString()
 {
     return(string.Format("msg=0x{0:x} ({1}) hwnd=0x{2:x} wparam=0x{3:x} lparam=0x{4:x} pt=0x{5:x}",
                          (int)Message, Message, HWnd.ToInt32(), WParam.ToInt32(), LParam.ToInt32(), Point));
 }
Exemplo n.º 13
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.InputLanguageChange:
                dwCharSet = (CharacterSet)(uint)wParam;
                goto case MessageType.Create;

            case MessageType.Create:
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    using (FontHandle font = Gdi.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet,
                                                            OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamilyType.DoNotCare, null))
                    {
                        dc.SelectObject(font);
                        dc.GetTextMetrics(out TextMetrics tm);
                        cxChar = tm.AverageCharWidth;
                        cyChar = tm.Height;
                        dc.SelectObject(StockFont.System);
                    }
                }
                goto CalculateSize;

            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;

CalculateSize:

                // calculate window size in characters
                cxBuffer = Math.Max(1, cxClient / cxChar);
                cyBuffer = Math.Max(1, cyClient / cyChar);

                // allocate memory for buffer and clear it
                pBuffer = new char[cxBuffer, cyBuffer];

                // set caret to upper left corner
                xCaret = 0;
                yCaret = 0;

                if (window == Windows.GetFocus())
                {
                    Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                }

                window.Invalidate(true);
                return(0);

            case MessageType.SetFocus:
                // create and show the caret
                window.CreateCaret(default, new Size(cxChar, cyChar));
                Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                window.ShowCaret();
                return(0);

            case MessageType.KillFocus:
                // hide and destroy the caret
                window.HideCaret();
                Windows.DestroyCaret();
                return(0);

            case MessageType.KeyDown:
                switch ((VirtualKey)wParam)
                {
                case VirtualKey.Home:
                    xCaret = 0;
                    break;

                case VirtualKey.End:
                    xCaret = cxBuffer - 1;
                    break;

                case VirtualKey.Prior:
                    yCaret = 0;
                    break;

                case VirtualKey.Next:
                    yCaret = cyBuffer - 1;
                    break;

                case VirtualKey.Left:
                    xCaret = Math.Max(xCaret - 1, 0);
                    break;

                case VirtualKey.Right:
                    xCaret = Math.Min(xCaret + 1, cxBuffer - 1);
                    break;

                case VirtualKey.Up:
                    yCaret = Math.Max(yCaret - 1, 0);
                    break;

                case VirtualKey.Down:
                    yCaret = Math.Min(yCaret + 1, cyBuffer - 1);
                    break;

                case VirtualKey.Delete:
                    for (int x = xCaret; x < cxBuffer - 1; x++)
                    {
                        pBuffer[x, yCaret] = pBuffer[x + 1, yCaret];
                    }

                    pBuffer[cxBuffer - 1, yCaret] = ' ';
                    window.HideCaret();
                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        using (FontHandle font = Gdi.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet,
                                                                OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamilyType.DoNotCare, null))
                        {
                            dc.SelectObject(font);
                            unsafe
                            {
                                fixed(char *c = &pBuffer[xCaret, yCaret])
                                dc.TextOut(
                                    new Point(xCaret * cxChar, yCaret * cyChar),
                                    new ReadOnlySpan <char>(c, cxBuffer - xCaret));
                            }
                            dc.SelectObject(StockFont.System);
                        }

                        window.ShowCaret();
                    }
                    break;
                }
                Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                return(0);

            case MessageType.Char:
                for (int i = 0; i < lParam.LowWord; i++)
                {
                    switch ((char)wParam)
                    {
                    case '\b':         // backspace
                        if (xCaret > 0)
                        {
                            xCaret--;
                            window.SendMessage(MessageType.KeyDown, (uint)VirtualKey.Delete, 1);
                        }
                        break;

                    case '\t':         // tab
                        do
                        {
                            window.SendMessage(MessageType.Char, ' ', 1);
                        } while (xCaret % 8 != 0);
                        break;

                    case '\n':         // line feed
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;

                    case '\r':         // carriage return
                        xCaret = 0;
                        if (++yCaret == cyBuffer)
                        {
                            yCaret = 0;
                        }
                        break;

                    case '\x1B':         // escape
                        for (int y = 0; y < cyBuffer; y++)
                        {
                            for (int x = 0; x < cxBuffer; x++)
                            {
                                pBuffer[x, y] = ' ';
                            }
                        }
                        xCaret = 0;
                        yCaret = 0;
                        window.Invalidate(false);
                        break;

                    default:         // character codes
                        pBuffer[xCaret, yCaret] = (char)wParam;
                        window.HideCaret();
                        using (DeviceContext dc = window.GetDeviceContext())
                        {
                            using (FontHandle font = Gdi.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet,
                                                                    OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamilyType.DoNotCare, null))
                            {
                                dc.SelectObject(font);
                                unsafe
                                {
                                    fixed(char *c = &pBuffer[xCaret, yCaret])
                                    dc.TextOut(
                                        new Point(xCaret * cxChar, yCaret * cyChar),
                                        new ReadOnlySpan <char>(c, 1));
                                }
                                dc.SelectObject(StockFont.System);
                            }

                            window.ShowCaret();
                        }

                        if (++xCaret == cxBuffer)
                        {
                            xCaret = 0;
                            if (++yCaret == cyBuffer)
                            {
                                yCaret = 0;
                            }
                        }
                        break;
                    }
                }
                Windows.SetCaretPosition(new Point(xCaret * cxChar, yCaret * cyChar));
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    using (FontHandle font = Gdi.CreateFont(0, 0, 0, 0, FontWeight.DoNotCare, false, false, false, dwCharSet,
                                                            OutputPrecision.Default, ClippingPrecision.Default, Quality.Default, FontPitch.FixedPitch, FontFamilyType.DoNotCare, null))
                    {
                        dc.SelectObject(font);
                        unsafe
                        {
                            for (int y = 0; y < cyBuffer; y++)
                                fixed(char *c = &pBuffer[0, y])
                                dc.TextOut(new Point(0, y * cyChar), new ReadOnlySpan <char>(c, cxBuffer));
                        }
                        dc.SelectObject(StockFont.System);
                    }
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 14
0
        private int _iDeltaPerLine, _iAccumDelta; // for mouse wheel logic

        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                base.WindowProcedure(window, message, wParam, lParam);

                // Fall through for mouse wheel information
                goto case MessageType.SettingChange;

            case MessageType.SettingChange:
                uint ulScrollLines = Windows.SystemParameters.GetWheelScrollLines();

                // ulScrollLines usually equals 3 or 0 (for no scrolling)
                // WHEEL_DELTA equals 120, so iDeltaPerLine will be 40
                if (ulScrollLines > 0)
                {
                    _iDeltaPerLine = (int)(120 / ulScrollLines);
                }
                else
                {
                    _iDeltaPerLine = 0;
                }
                return(0);

            case MessageType.MouseWheel:
                if (_iDeltaPerLine == 0)
                {
                    break;
                }
                _iAccumDelta += (short)wParam.HighWord;     // 120 or -120
                while (_iAccumDelta >= _iDeltaPerLine)
                {
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.LineUp, 0);
                    _iAccumDelta -= _iDeltaPerLine;
                }
                while (_iAccumDelta <= -_iDeltaPerLine)
                {
                    window.SendMessage(MessageType.VerticalScroll, (uint)ScrollCommand.LineDown, 0);
                    _iAccumDelta += _iDeltaPerLine;
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 15
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                _initialMonitor = window.MonitorFromWindow();
                _screen         = Windows.GetMonitorInfo(_initialMonitor).Monitor;
                window.SetTimer(_timerId, 200);
                return(0);

            case MessageType.Size:
                _client = new Rectangle(default, new Message.Size(wParam, lParam).NewSize);
                return(0);

            case MessageType.Timer:
                // Update via timer if we aren't primarily on the main monitor
                if (window.MonitorFromWindow() != _initialMonitor)
                {
                    window.Invalidate();
                }
                return(0);

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

            case MessageType.Paint:
                using (DeviceContext clientDC = window.BeginPaint())
                    using (DeviceContext screenDC = Gdi.GetDeviceContext())
                    {
                        clientDC.SetStretchBlitMode(StretchMode.HalfTone);
                        screenDC.StretchBlit(clientDC, _screen, _client, RasterOperation.Common.SourceCopy);
                    }
                return(0);

            case MessageType.Destroy:
                window.KillTimer(_timerId);
                break;
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 16
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.MoveTo(new Point(0, cyClient / 2));
                    dc.LineTo(new Point(cxClient, cyClient / 2));

                    for (int i = 0; i < apt.Length; i++)
                    {
                        apt[i].X = i * cxClient / apt.Length;
                        apt[i].Y = (int)(cyClient / 2 * (1 - Math.Sin(Math.PI * 2 * i / apt.Length)));
                    }
                    dc.Polyline(apt);
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 17
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Size:
                cxBlock = lParam.LowWord / DIVISIONS;
                cyBlock = lParam.HighWord / DIVISIONS;
                return(0);

            case MessageType.LeftButtonDown:
                int x = lParam.LowWord / cxBlock;
                int y = lParam.HighWord / cyBlock;
                if (x < DIVISIONS && y < DIVISIONS)
                {
                    fState[x, y] ^= true;
                    Rectangle rect = Rectangle.FromLTRB
                                     (
                        x * cxBlock,
                        y * cyBlock,
                        (x + 1) * cxBlock,
                        (y + 1) * cyBlock
                                     );
                    window.InvalidateRectangle(rect, false);
                }
                else
                {
                    Windows.MessageBeep(0);
                }

                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    for (x = 0; x < DIVISIONS; x++)
                    {
                        for (y = 0; y < DIVISIONS; y++)
                        {
                            dc.Rectangle(new Rectangle(
                                             x * cxBlock, y * cyBlock, (x + 1) * cxBlock, (y + 1) * cyBlock));

                            if (fState[x, y])
                            {
                                dc.MoveTo(new Point(x * cxBlock, y * cyBlock));
                                dc.LineTo(new Point((x + 1) * cxBlock, (y + 1) * cyBlock));
                                dc.MoveTo(new Point(x * cxBlock, (y + 1) * cyBlock));
                                dc.LineTo(new Point((x + 1) * cxBlock, y * cyBlock));
                            }
                        }
                    }
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 18
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                _chunk = _sb.GetChunk();
                goto case MessageType.DisplayChange;

            case MessageType.DisplayChange:
                // Get maximum size of client area
                cyClientMax = Windows.GetSystemMetrics(SystemMetric.MaximizedHeight);

                // Get character size for fixed-pitch font
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    dc.SelectObject(StockFont.SystemFixed);
                    dc.GetTextMetrics(out TextMetrics tm);
                    cyChar = tm.Height;
                }

                cLinesMax = cyClientMax / cyChar;
                pmsg      = new WindowMessage[cLinesMax];
                cLines    = 0;
                goto CalculateScroll;

            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;

CalculateScroll:

                rectScroll = Rectangle.FromLTRB(0, cyChar, cxClient, cyChar * (cyClient / cyChar));
                window.Invalidate(true);

                return(0);

            case MessageType.KeyDown:
            case MessageType.KeyUp:
            case MessageType.Char:
            case MessageType.DeadChar:
            case MessageType.SystemKeyDown:
            case MessageType.SystemKeyUp:
            case MessageType.SystemChar:
            case MessageType.SystemDeadChar:
                // Rearrange storage array
                for (int i = cLinesMax - 1; i > 0; i--)
                {
                    pmsg[i] = pmsg[i - 1];
                }
                // Store new message
                pmsg[0] = new WindowMessage(window, message, wParam, lParam);
                cLines  = Math.Min(cLines + 1, cLinesMax);

                // Scroll up the display
                window.ScrollWindow(new Point(0, -cyChar), rectScroll, rectScroll);
                break;     // i.e., call DefWindowProc so Sys messages work

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SelectObject(StockFont.SystemFixed);
                    dc.SetBackgroundMode(BackgroundMode.Transparent);
                    dc.TextOut(default, "Message        Key       Char     Repeat Scan Ext ALT Prev Tran".AsSpan());
                    dc.TextOut(default, "_______        ___       ____     ______ ____ ___ ___ ____ ____".AsSpan());
                    for (int i = 0; i < Math.Min(cLines, cyClient / cyChar - 1); i++)
                    {
                        bool iType;
                        switch (pmsg[i].Type)
                        {
                        case MessageType.Char:
                        case MessageType.SystemChar:
                        case MessageType.DeadChar:
                        case MessageType.SystemDeadChar:
                            iType = true;
                            break;

                        default:
                            iType = false;
                            break;
                        }

                        _sb.Clear();
                        _sb.AppendFormat(iType
                                ? "{0,-13} {1,3} {2,15} {3,6} {4,4} {5,3} {6,3} {7,4} {8,4}"
                                : "{0,-13} {1,3} {2,-15} {3,6} {4,4} {5,3} {6,3} {7,4} {8,4}  VirtualKey: {9}",
                                         pmsg[i].Type,
                                         pmsg[i].WParam.ToString(),
                                         iType
                                        ? $"0x{((uint)pmsg[i].WParam):X4} {(char)(uint)pmsg[i].WParam}"
                                        : Windows.GetKeyNameText(pmsg[i].LParam),
                                         pmsg[i].LParam.LowWord,
                                         pmsg[i].LParam.HighWord & 0xFF,
                                         (0x01000000 & pmsg[i].LParam) != 0 ? "Yes" : "No",
                                         (0x20000000 & pmsg[i].LParam) != 0 ? "Yes" : "No",
                                         (0x40000000 & pmsg[i].LParam) != 0 ? "Down" : "Up",
                                         (0x80000000 & pmsg[i].LParam) != 0 ? "Up" : "Down",
                                         (VirtualKey)pmsg[i].WParam);

                        dc.TextOut(new Point(0, (cyClient / cyChar - 1 - i) * cyChar), _chunk.Span.Slice(0, _sb.Length));
                    }
                }
                return(0);
            }
Exemplo n.º 19
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;

                CursorHandle hCursor = Windows.SetCursor(CursorId.Wait);
                Windows.ShowCursor(true);

                hRgnClip.Dispose();

                Span <RegionHandle> hRgnTemp = stackalloc RegionHandle[6];

                hRgnTemp[0] = Gdi.CreateEllipticRegion(Rectangle.FromLTRB(0, cyClient / 3, cxClient / 2, 2 * cyClient / 3));
                hRgnTemp[1] = Gdi.CreateEllipticRegion(Rectangle.FromLTRB(cxClient / 2, cyClient / 3, cxClient, 2 * cyClient / 3));
                hRgnTemp[2] = Gdi.CreateEllipticRegion(Rectangle.FromLTRB(cxClient / 3, 0, 2 * cxClient / 3, cyClient / 2));
                hRgnTemp[3] = Gdi.CreateEllipticRegion(Rectangle.FromLTRB(cxClient / 3, cyClient / 2, 2 * cxClient / 3, cyClient));
                hRgnTemp[4] = Gdi.CreateRectangleRegion(Rectangle.FromLTRB(0, 0, 1, 1));
                hRgnTemp[5] = Gdi.CreateRectangleRegion(Rectangle.FromLTRB(0, 0, 1, 1));
                hRgnClip    = Gdi.CreateRectangleRegion(Rectangle.FromLTRB(0, 0, 1, 1));
                hRgnTemp[4].CombineRegion(hRgnTemp[0], hRgnTemp[1], CombineRegionMode.Or);
                hRgnTemp[5].CombineRegion(hRgnTemp[2], hRgnTemp[3], CombineRegionMode.Or);
                hRgnClip.CombineRegion(hRgnTemp[4], hRgnTemp[5], CombineRegionMode.Xor);
                for (int i = 0; i < 6; i++)
                {
                    hRgnTemp[i].Dispose();
                }

                Windows.SetCursor(hCursor);
                Windows.ShowCursor(false);

                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SetViewportOrigin(new Point(cxClient / 2, cyClient / 2));
                    dc.SelectClippingRegion(hRgnClip);

                    double fRadius = Hypotenuse(cxClient / 2.0, cyClient / 2.0);

                    for (double fAngle = 0.0; fAngle < TWO_PI; fAngle += TWO_PI / 360)
                    {
                        dc.MoveTo(default);
                        dc.LineTo(new Point(
                                      (int)(fRadius * Math.Cos(fAngle) + 0.5),
                                      (int)(-fRadius * Math.Sin(fAngle) + 0.5)));
                    }
                }
Exemplo n.º 20
0
 /// <summary>
 ///     Determines whether the <see href="WParam"/> field of this window message matches the specified <paramref name="wParam"/>.
 /// </summary>
 /// <param name="wParam">
 ///     <see href="User.WParam"/> value to check for equality.
 /// </param>
 /// <returns>
 ///     <c>true</c> if the <see href="WParam"/> field of this window message matches the specified <paramref name="wParam"/>; otherwise <c>false</c>.
 /// </returns>
 public bool Is(WParam wParam)
 {
     return(WParamInt64Value == wParam.ToInt64());
 }
Exemplo n.º 21
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                window.SetTimer(ID_TIMER, 1000);
                return(0);

            case MessageType.Timer:
                Windows.MessageBeep();
                fFlipFlop = !fFlipFlop;
                window.Invalidate();
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    using (BrushHandle brush = Gdi.CreateSolidBrush(fFlipFlop ? Color.Red : Color.Blue))
                    {
                        dc.FillRectangle(window.GetClientRectangle(), brush);
                    }
                }
                return(0);

            case MessageType.Destroy:
                window.KillTimer(ID_TIMER);
                break;
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 22
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                window.SetTimer(ID_TIMER, 100);
                return(0);

            case MessageType.Timer:
                Point pt = Windows.GetCursorPosition();

                using (DeviceContext dc = Gdi.CreateDesktopDeviceContext())
                {
                    cr = dc.GetPixel(pt);

                    if (cr != crLast)
                    {
                        crLast = cr;
                        window.GetDeviceContext().SetBackgroundColor(cr);
                        window.Invalidate(erase: false);
                    }
                }
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SelectObject(StockFont.SystemFixed);
                    Rectangle rc = window.GetClientRectangle();
                    dc.FillRectangle(rc, dc.GetCurrentBrush());
                    dc.DrawText($"0x{cr.R:X2} 0x{cr.G:X2} 0x{cr.B:X2}".AsSpan(), rc,
                                TextFormat.SingleLine | TextFormat.Center | TextFormat.VerticallyCenter);
                }
                return(0);

            case MessageType.Destroy:
                window.KillTimer(ID_TIMER);
                break;
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 23
0
            // Overriding the callback method will allow us to provide our own custom behavior
            protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
            {
                switch (message)
                {
                // The Paint message is sent when the Window contents need drawn.
                case MessageType.Paint:

                    // Drawing is done in a Device Context by calling BeginPaint(). When the
                    // DeviceContext is disposed it will call EndPaint().
                    using (DeviceContext dc = window.BeginPaint())
                    {
                        Rectangle client = window.GetClientRectangle();

                        // The default font is really small on modern PCs, so we'll take the extra step
                        // to select a font into our device context before drawing the text.
                        using FontHandle font = Gdi.CreateFont(
                                  height: client.Height / 5,
                                  family: FontFamilyType.Swiss);
                        dc.SelectObject(font);

                        // Draw the given text in the middle of the client area of the Window.
                        dc.DrawText(
                            "Hello, .NET Core!",
                            client,
                            TextFormat.SingleLine | TextFormat.Center | TextFormat.VerticallyCenter);

                        // Put the system font back as we're going to dispose our font
                        dc.SelectObject(StockFont.System);
                    }

                    // Return 0 to indicate we've handled the message
                    return(0);
                }

                // Let the base class handle any other messages
                return(base.WindowProcedure(window, message, wParam, lParam));
            }
Exemplo n.º 24
0
        private static LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                s_baseUnits = Windows.GetDialogBaseUnits();
                s_btnWidth  = s_baseUnits.Width * 8;
                s_btnHeight = s_baseUnits.Height * 4;

                // Create the owner-draw pushbuttons
                var createMessage = new Message.Create(lParam);

                s_hwndSmaller = Windows.CreateWindow("button",
                                                     style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ButtonStyles.OwnerDrawn,
                                                     bounds: new Rectangle(0, 0, s_btnWidth, s_btnHeight),
                                                     parentWindow: window,
                                                     menuHandle: (MenuHandle)ID_SMALLER,
                                                     instance: createMessage.Instance);
                s_hwndLarger = Windows.CreateWindow("button",
                                                    style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ButtonStyles.OwnerDrawn,
                                                    bounds: new Rectangle(0, 0, s_btnWidth, s_btnHeight),
                                                    parentWindow: window,
                                                    menuHandle: (MenuHandle)ID_LARGER,
                                                    instance: createMessage.Instance);

                return(0);

            case MessageType.Size:
                s_cxClient = lParam.LowWord;
                s_cyClient = lParam.HighWord;

                // Move the buttons to the new center
                s_hwndSmaller.MoveWindow(
                    new Rectangle(s_cxClient / 2 - 3 * s_btnWidth / 2, s_cyClient / 2 - s_btnHeight / 2, s_btnWidth, s_btnHeight),
                    repaint: true);
                s_hwndLarger.MoveWindow(
                    new Rectangle(s_cxClient / 2 + s_btnWidth / 2, s_cyClient / 2 - s_btnHeight / 2, s_btnWidth, s_btnHeight),
                    repaint: true);
                return(0);

            case MessageType.Command:
                Rectangle rc = window.GetWindowRectangle();

                // Make the window 10% smaller or larger
                switch ((int)(uint)wParam)
                {
                case ID_SMALLER:
                    rc.Inflate(rc.Width / -10, rc.Height / -10);
                    break;

                case ID_LARGER:
                    rc.Inflate(rc.Width / 10, rc.Height / 10);
                    break;
                }

                window.MoveWindow(rc, repaint: true);
                return(0);

            case MessageType.DrawItem:

                var drawItemMessage = new Message.DrawItem(lParam);

                // Fill area with white and frame it black
                using (DeviceContext dc = drawItemMessage.DeviceContext)
                {
                    Rectangle rect = drawItemMessage.ItemRectangle;

                    dc.FillRectangle(rect, StockBrush.White);
                    dc.FrameRectangle(rect, StockBrush.Black);

                    // Draw inward and outward black triangles
                    int cx = rect.Right - rect.Left;
                    int cy = rect.Bottom - rect.Top;

                    Point[] pt = new Point[3];

                    switch ((int)drawItemMessage.ControlId)
                    {
                    case ID_SMALLER:
                        pt[0].X = 3 * cx / 8; pt[0].Y = 1 * cy / 8;
                        pt[1].X = 5 * cx / 8; pt[1].Y = 1 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 3 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 7 * cx / 8; pt[0].Y = 3 * cy / 8;
                        pt[1].X = 7 * cx / 8; pt[1].Y = 5 * cy / 8;
                        pt[2].X = 5 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 5 * cx / 8; pt[0].Y = 7 * cy / 8;
                        pt[1].X = 3 * cx / 8; pt[1].Y = 7 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 5 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 1 * cx / 8; pt[0].Y = 5 * cy / 8;
                        pt[1].X = 1 * cx / 8; pt[1].Y = 3 * cy / 8;
                        pt[2].X = 3 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        break;

                    case ID_LARGER:
                        pt[0].X = 5 * cx / 8; pt[0].Y = 3 * cy / 8;
                        pt[1].X = 3 * cx / 8; pt[1].Y = 3 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 1 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 5 * cx / 8; pt[0].Y = 5 * cy / 8;
                        pt[1].X = 5 * cx / 8; pt[1].Y = 3 * cy / 8;
                        pt[2].X = 7 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 3 * cx / 8; pt[0].Y = 5 * cy / 8;
                        pt[1].X = 5 * cx / 8; pt[1].Y = 5 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 7 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 3 * cx / 8; pt[0].Y = 3 * cy / 8;
                        pt[1].X = 3 * cx / 8; pt[1].Y = 5 * cy / 8;
                        pt[2].X = 1 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        break;
                    }

                    // Invert the rectangle if the button is selected
                    if ((drawItemMessage.ItemState & OwnerDrawStates.Selected) != 0)
                    {
                        dc.InvertRectangle(rect);
                    }

                    if ((drawItemMessage.ItemState & OwnerDrawStates.Focus) != 0)
                    {
                        rect = Rectangle.FromLTRB(
                            rect.Left + cx / 16,
                            rect.Top + cy / 16,
                            rect.Right - cx / 16,
                            rect.Bottom - cy / 16);

                        dc.DrawFocusRectangle(rect);
                    }
                }
                return(0);

            case MessageType.Destroy:
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 25
0
        protected unsafe override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                hwndEdit = Windows.CreateWindow("edit", "",
                                                WindowStyles.Child | WindowStyles.Visible | WindowStyles.HorizontalScroll | WindowStyles.VerticalScroll
                                                | WindowStyles.Border | (WindowStyles)EditStyles.Left | (WindowStyles)EditStyles.Multiline
                                                | (WindowStyles)EditStyles.AutoHorizontalScroll | (WindowStyles)EditStyles.AutoVerticalScroll,
                                                ExtendedWindowStyles.Default, new Rectangle(), window, (MenuHandle)ID_EDIT, ModuleInstance, IntPtr.Zero);
                return(0);

            case MessageType.SetFocus:
                hwndEdit.SetFocus();
                return(0);

            case MessageType.Size:
                hwndEdit.MoveWindow(new Rectangle(0, 0, lParam.LowWord, lParam.HighWord), repaint: true);
                return(0);

            case MessageType.Command:
                if (wParam.LowWord == ID_EDIT &&
                    (wParam.HighWord == (ushort)EditNotification.ErrorSpace || wParam.HighWord == (ushort)EditNotification.MaxText))
                {
                    window.MessageBox("Edit control out of space.", "PopPad1", MessageBoxType.Ok | MessageBoxType.IconStop);
                }
                return(0);

            case MessageType.Destroy:
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 26
0
            protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
            {
                switch (message)
                {
                case MessageType.Create:
                    _editClass = new EditClass(EditStyles.Multiline | EditStyles.Left
                                               | EditStyles.AutoHorizontalScroll | EditStyles.AutoVerticalScroll);
                    _editHandle = _editClass.CreateWindow(
                        style: WindowStyles.Child | WindowStyles.Visible | WindowStyles.HorizontalScroll
                        | WindowStyles.VerticalScroll | WindowStyles.Border,
                        parentWindow: window);
                    return(0);

                case MessageType.SetFocus:
                    _editHandle.SetFocus();
                    return(0);

                case MessageType.Size:
                    var size = new Message.Size(wParam, lParam);
                    _editHandle.MoveWindow(new Rectangle(new Point(), size.NewSize), repaint: true);
                    return(0);
                }

                return(base.WindowProcedure(window, message, wParam, lParam));
            }
Exemplo n.º 27
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                window.SetTimer(ID_TIMER, 1000);
                _previousTime = SystemInformation.GetLocalTime();
                return(0);

            case MessageType.Size:
                _clientSize = new Message.Size(wParam, lParam).NewSize;
                return(0);

            case MessageType.Timer:
                SystemTime time         = SystemInformation.GetLocalTime();
                bool       drawAllHands = time.Hour != _previousTime.Hour ||
                                          time.Minute != _previousTime.Minute;
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    SetIsotropic(dc);
                    DrawHands(dc, _previousTime, erase: true, drawAllHands);
                    DrawHands(dc, time);
                }
                _previousTime = time;
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    SetIsotropic(dc);
                    DrawClock(dc);
                    DrawHands(dc, _previousTime);
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 28
0
 public Size(WParam wParam, LParam lParam)
 {
     NewSize  = new System.Drawing.Size(lParam.LowWord, lParam.HighWord);
     SizeType = (SizeType)(int)wParam;
 }
Exemplo n.º 29
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    dc.GetTextMetrics(out TextMetrics tm);
                    cxChar = tm.AverageCharWidth;
                    cxCaps = ((tm.PitchAndFamily.PitchTypes & FontPitchTypes.VariablePitch) != 0 ? 3 : 2) * cxChar / 2;
                    cyChar = tm.Height + tm.ExternalLeading;
                }
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    int i = 0;
                    foreach (SystemMetric metric in Metrics.SystemMetrics.Keys)
                    {
                        dc.TextOut(new Point(0, cyChar * i), metric.ToString().AsSpan());
                        dc.TextOut(new Point(22 * cxCaps, cyChar * i), Metrics.SystemMetrics[metric].AsSpan());
                        dc.SetTextAlignment(new TextAlignment(TextAlignment.Horizontal.Right, TextAlignment.Vertical.Top));
                        dc.TextOut(new Point(22 * cxCaps + 40 * cxChar, cyChar * i), Windows.GetSystemMetrics(metric).ToString().AsSpan());
                        dc.SetTextAlignment(new TextAlignment(TextAlignment.Horizontal.Left, TextAlignment.Vertical.Top));
                        i++;
                    }
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 30
0
        protected unsafe override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                _baseUnits = Windows.GetDialogBaseUnits();
                _btnWidth  = _baseUnits.Width * 8;
                _btnHeight = _baseUnits.Height * 4;

                // Create the owner-draw pushbuttons
                _hwndSmaller = Windows.CreateWindow("button", "",
                                                    WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ButtonStyles.OwnerDrawn,
                                                    ExtendedWindowStyles.Default,
                                                    new Rectangle(0, 0, _btnWidth, _btnHeight),
                                                    window, (MenuHandle)ID_SMALLER, ModuleInstance, IntPtr.Zero);

                _hwndLarger = Windows.CreateWindow("button", "",
                                                   WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ButtonStyles.OwnerDrawn,
                                                   ExtendedWindowStyles.Default,
                                                   new Rectangle(0, 0, _btnWidth, _btnHeight),
                                                   window, (MenuHandle)ID_LARGER, ModuleInstance, IntPtr.Zero);
                return(0);

            case MessageType.Size:
                _cxClient = lParam.LowWord;
                _cyClient = lParam.HighWord;

                // Move the buttons to the new center
                _hwndSmaller.MoveWindow(
                    new Rectangle(_cxClient / 2 - 3 * _btnWidth / 2, _cyClient / 2 - _btnHeight / 2, _btnWidth, _btnHeight),
                    repaint: true);
                _hwndLarger.MoveWindow(
                    new Rectangle(_cxClient / 2 + _btnWidth / 2, _cyClient / 2 - _btnHeight / 2, _btnWidth, _btnHeight),
                    repaint: true);
                return(0);

            case MessageType.Command:
                Rectangle rc = window.GetWindowRectangle();

                // Make the window 10% smaller or larger
                switch ((int)(uint)wParam)
                {
                case ID_SMALLER:
                    rc.Inflate(rc.Width / -10, rc.Height / -10);
                    break;

                case ID_LARGER:
                    rc.Inflate(rc.Width / 10, rc.Height / 10);
                    break;
                }

                window.MoveWindow(new Rectangle(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top), repaint: true);
                return(0);

            case MessageType.DrawItem:
                DRAWITEMSTRUCT *pdis = (DRAWITEMSTRUCT *)lParam;

                // Fill area with white and frame it black
                using (DeviceContext dc = new DeviceContext(pdis->hDC))
                {
                    Rectangle rect = pdis->rcItem;

                    dc.FillRectangle(rect, StockBrush.White);
                    dc.FrameRectangle(rect, StockBrush.Black);

                    // Draw inward and outward black triangles
                    int cx = rect.Right - rect.Left;
                    int cy = rect.Bottom - rect.Top;

                    Point[] pt = new Point[3];

                    switch ((int)pdis->CtlID)
                    {
                    case ID_SMALLER:
                        pt[0].X = 3 * cx / 8; pt[0].Y = 1 * cy / 8;
                        pt[1].X = 5 * cx / 8; pt[1].Y = 1 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 3 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 7 * cx / 8; pt[0].Y = 3 * cy / 8;
                        pt[1].X = 7 * cx / 8; pt[1].Y = 5 * cy / 8;
                        pt[2].X = 5 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 5 * cx / 8; pt[0].Y = 7 * cy / 8;
                        pt[1].X = 3 * cx / 8; pt[1].Y = 7 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 5 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 1 * cx / 8; pt[0].Y = 5 * cy / 8;
                        pt[1].X = 1 * cx / 8; pt[1].Y = 3 * cy / 8;
                        pt[2].X = 3 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        break;

                    case ID_LARGER:
                        pt[0].X = 5 * cx / 8; pt[0].Y = 3 * cy / 8;
                        pt[1].X = 3 * cx / 8; pt[1].Y = 3 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 1 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 5 * cx / 8; pt[0].Y = 5 * cy / 8;
                        pt[1].X = 5 * cx / 8; pt[1].Y = 3 * cy / 8;
                        pt[2].X = 7 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 3 * cx / 8; pt[0].Y = 5 * cy / 8;
                        pt[1].X = 5 * cx / 8; pt[1].Y = 5 * cy / 8;
                        pt[2].X = 4 * cx / 8; pt[2].Y = 7 * cy / 8;
                        Triangle(dc, pt);
                        pt[0].X = 3 * cx / 8; pt[0].Y = 3 * cy / 8;
                        pt[1].X = 3 * cx / 8; pt[1].Y = 5 * cy / 8;
                        pt[2].X = 1 * cx / 8; pt[2].Y = 4 * cy / 8;
                        Triangle(dc, pt);
                        break;
                    }

                    // Invert the rectangle if the button is selected
                    if ((pdis->itemState & OwnerDrawStates.Selected) != 0)
                    {
                        dc.InvertRectangle(rect);
                    }

                    if ((pdis->itemState & OwnerDrawStates.Focus) != 0)
                    {
                        rect = Rectangle.FromLTRB(
                            rect.Left + cx / 16,
                            rect.Top + cy / 16,
                            rect.Right - cx / 16,
                            rect.Bottom - cy / 16);

                        dc.DrawFocusRectangle(rect);
                    }
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }