/// <summary>
        /// Creates a solid brush, and sets it as a background brush.
        /// </summary>
        private void SetBackgroundBrush()
        {
            if (_nativeBackgroundBrush != null)
            {
                _nativeBackgroundBrush.Dispose();
            }

            // using some native tricks so we can set our background
            // brush to match our back color, so everything draws nicely on resize.
            _nativeBackgroundBrush = this.CreateNativeSolidBrush(BackColor);
            this.SetBackgroundBrush(_nativeBackgroundBrush);
        }
Example #2
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                hBrushRed = Windows.CreateSolidBrush(255, 0, 0);
                window.SetTimer(ID_TIMER, 1000);
                return(0);

            case WindowMessage.SettingChange:
                f24Hour   = Windows.LocaleInfo.GetIs24HourClock();
                fSuppress = Windows.LocaleInfo.GetHoursHaveLeadingZeros();
                window.Invalidate(true);
                return(0);

            case WindowMessage.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

            case WindowMessage.Timer:
                window.Invalidate(true);
                return(0);

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SetMapMode(MapMode.Isotropic);
                    dc.SetWindowExtents(276, 72);
                    dc.SetViewportExtents(cxClient, cyClient);
                    dc.SetWindowOrigin(138, 36);
                    dc.SetViewportOrigin(cxClient / 2, cyClient / 2);
                    dc.SelectObject(StockPen.Null);
                    dc.SelectObject(hBrushRed);
                    DisplayTime(dc, f24Hour, fSuppress);
                }
                return(0);

            case WindowMessage.Destroy:
                window.KillTimer(ID_TIMER);
                hBrushRed.Dispose();
                Windows.PostQuitMessage(0);
                return(0);
            }

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Example #3
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Create:
                hBrushRed = Gdi.CreateSolidBrush(Color.Red);
                window.SetTimer(ID_TIMER, 1000);
                return(0);

            case MessageType.SettingChange:
                f24Hour   = Windows.LocaleInfo.GetIs24HourClock();
                fSuppress = Windows.LocaleInfo.GetHoursHaveLeadingZeros();
                window.Invalidate(true);
                return(0);

            case MessageType.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

            case MessageType.Timer:
                window.Invalidate(true);
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SetMappingMode(MappingMode.Isotropic);
                    dc.SetWindowExtents(new Size(276, 72));
                    dc.SetViewportExtents(new Size(cxClient, cyClient));
                    dc.SetWindowOrigin(new Point(138, 36));
                    dc.SetViewportOrigin(new Point(cxClient / 2, cyClient / 2));
                    dc.SelectObject(StockPen.Null);
                    dc.SelectObject(hBrushRed);
                    DisplayTime(dc, f24Hour, fSuppress);
                }
                return(0);

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

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