Esempio n. 1
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));
        }