Exemplo n.º 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.LeftButtonDown:
                window.SetWindowLong(0, (IntPtr)(1 ^ (int)window.GetWindowLong(0)));
                window.Invalidate(false);
                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(default);
                        dc.LineTo(new Point(rect.Right, rect.Bottom));
                        dc.MoveTo(new Point(0, rect.Bottom));
                        dc.LineTo(new Point(rect.Right, 0));
                    }
                }
Exemplo n.º 2
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.º 3
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.º 4
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.LeftButtonDown:
                window.SetWindowLong(0, (IntPtr)(1 ^ (int)window.GetWindowLong(0)));
                window.Invalidate(false);
                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);
                    }
                }
                return(0);
            }
            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 5
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

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

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 6
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.º 7
0
        private static LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.Size:
                s_cxClient = lParam.LowWord;
                s_cyClient = lParam.HighWord;
                return(0);

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

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 8
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.º 9
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                window.SetTimer(ID_TIMER, 1000);
                return(0);

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

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    RECT rect = window.GetClientRectangle();
                    using (BrushHandle brush = fFlipFlop ? Windows.CreateSolidBrush(255, 0, 0) : Windows.CreateSolidBrush(0, 0, 255))
                    {
                        dc.FillRectangle(rect, brush);
                    }
                }
                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 10
0
        private 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.º 11
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

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

                    POINT[] apt = new POINT[1000];
                    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);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 12
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.LeftButtonDown:
                _ptBeg.X = _ptEnd.X = lParam.LowWord;
                _ptBeg.Y = _ptEnd.Y = lParam.HighWord;
                DrawBoxOutline(window, _ptBeg, _ptEnd);
                window.SetCapture();
                Windows.SetCursor(CursorId.Cross);
                _fBlocking = true;
                return(0);

            case MessageType.MouseMove:
                if (_fBlocking)
                {
                    Windows.SetCursor(CursorId.Cross);
                    DrawBoxOutline(window, _ptBeg, _ptEnd);
                    _ptEnd.X = lParam.LowWord;
                    _ptEnd.Y = lParam.HighWord;
                    DrawBoxOutline(window, _ptBeg, _ptEnd);
                }
                return(0);

            case MessageType.LeftButtonUp:
                if (_fBlocking)
                {
                    DrawBoxOutline(window, _ptBeg, _ptEnd);
                    _ptBoxBeg   = _ptBeg;
                    _ptBoxEnd.X = lParam.LowWord;
                    _ptBoxEnd.Y = lParam.HighWord;
                    Windows.ReleaseCapture();
                    Windows.SetCursor(CursorId.Arrow);
                    _fBlocking = false;
                    _fValidBox = true;
                    window.Invalidate(true);
                }
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    if (_fValidBox)
                    {
                        dc.SelectObject(StockBrush.Black);
                        dc.Rectangle(Rectangle.FromLTRB(_ptBoxBeg.X, _ptBoxBeg.Y, _ptBoxEnd.X, _ptBoxEnd.Y));
                    }
                    if (_fBlocking)
                    {
                        dc.SetRasterOperation(PenMixMode.Not);
                        dc.SelectObject(StockBrush.Null);
                        dc.Rectangle(Rectangle.FromLTRB(_ptBeg.X, _ptBeg.Y, _ptEnd.X, _ptEnd.Y));
                    }
                }
                return(0);
            }

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

                _apt[0].X = cxClient / 4;
                _apt[0].Y = cyClient / 2;
                _apt[1].X = cxClient / 2;
                _apt[1].Y = cyClient / 4;
                _apt[2].X = cxClient / 2;
                _apt[2].Y = 3 * cyClient / 4;
                _apt[3].X = 3 * cxClient / 4;
                _apt[3].Y = cyClient / 2;

                return(0);

            case MessageType.LeftButtonDown:
            case MessageType.RightButtonDown:
            case MessageType.MouseMove:
                MouseKey mk = (MouseKey)wParam.LowWord;
                if ((mk & (MouseKey.LeftButton | MouseKey.RightButton)) != 0)
                {
                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        dc.SelectObject(StockPen.White);
                        DrawBezier(dc, _apt);

                        if ((mk & MouseKey.LeftButton) != 0)
                        {
                            _apt[1].X = lParam.LowWord;
                            _apt[1].Y = lParam.HighWord;
                        }

                        if ((mk & MouseKey.RightButton) != 0)
                        {
                            _apt[2].X = lParam.LowWord;
                            _apt[2].Y = lParam.HighWord;
                        }

                        dc.SelectObject(StockPen.Black);
                        DrawBezier(dc, _apt);
                    }
                }
                return(0);

            case MessageType.Paint:
                window.Invalidate(true);
                using (DeviceContext dc = window.BeginPaint())
                {
                    DrawBezier(dc, _apt);
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 14
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Size:
                cxBlock = lParam.LowWord / DIVISIONS;
                cyBlock = lParam.HighWord / DIVISIONS;
                return(0);

            case WindowMessage.LeftButtonDown:
                int x = lParam.LowWord / cxBlock;
                int y = lParam.HighWord / cyBlock;
                if (x < DIVISIONS && y < DIVISIONS)
                {
                    fState[x, y] ^= true;
                    RECT rect = new RECT
                    {
                        left   = x * cxBlock,
                        top    = y * cyBlock,
                        right  = (x + 1) * cxBlock,
                        bottom = (y + 1) * cyBlock
                    };
                    window.InvalidateRectangle(rect, false);
                }
                else
                {
                    ErrorMethods.MessageBeep(0);
                }

                return(0);

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    for (x = 0; x < DIVISIONS; x++)
                    {
                        for (y = 0; y < DIVISIONS; y++)
                        {
                            dc.Rectangle(x * cxBlock, y * cyBlock,
                                         (x + 1) * cxBlock, (y + 1) * cyBlock);
                            if (fState[x, y])
                            {
                                dc.MoveTo(x * cxBlock, y * cyBlock);
                                dc.LineTo((x + 1) * cxBlock, (y + 1) * cyBlock);
                                dc.MoveTo(x * cxBlock, (y + 1) * cyBlock);
                                dc.LineTo((x + 1) * cxBlock, y * cyBlock);
                            }
                        }
                    }
                }
                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 15
0
 public DoubleBufferPaint(WindowHandle window)
 {
     _client       = window.GetClientRectangle();
     _originalDC   = window.BeginPaint();
     DeviceContext = _originalDC.CreateCompatibleDeviceContext();
     _bitmap       = DeviceContext.CreateCompatibleBitmap(_client.Size);
     DeviceContext.SelectObject(_bitmap);
 }
Exemplo n.º 16
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.º 17
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.LeftButtonDown:
                iCount = 0;
                window.Invalidate(true);
                return(0);

            case WindowMessage.MouseMove:
                // Machines are way to fast to make this look interesting now, adding TakeEvery
                if ((MouseKey)wParam == MouseKey.LeftButton && iCount < MAXPOINTS && (sampleCount++ % TakeEvery == 0))
                {
                    pt[iCount].x   = lParam.LowWord;
                    pt[iCount++].y = lParam.HighWord;

                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        dc.SetPixel(lParam.LowWord, lParam.HighWord, 0);
                    }
                }
                return(0);

            case WindowMessage.LeftButtonUp:
                window.Invalidate(false);
                return(0);

            case WindowMessage.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    Windows.SetCursor(CursorId.Wait);
                    Windows.ShowCursor(true);

                    for (int i = 0; i < iCount - 1; i++)
                    {
                        for (int j = i + 1; j < iCount; j++)
                        {
                            dc.MoveTo(pt[i].x, pt[i].y);
                            dc.LineTo(pt[j].x, pt[j].y);
                        }
                    }

                    Windows.ShowCursor(false);
                    Windows.SetCursor(CursorId.Arrow);
                }
                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 18
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.º 19
0
        protected override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam)
        {
            switch (message)
            {
            case MessageType.LeftButtonDown:
                iCount = 0;
                window.Invalidate(true);
                return(0);

            case MessageType.MouseMove:
                // Machines are way to fast to make this look interesting now, adding TakeEvery
                if ((MouseKey)wParam == MouseKey.LeftButton && iCount < MAXPOINTS && (sampleCount++ % TakeEvery == 0))
                {
                    Point point = new Point(lParam.LowWord, lParam.HighWord);
                    pt[iCount++] = point;

                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        dc.SetPixel(point, default);
                    }
                }
                return(0);

            case MessageType.LeftButtonUp:
                window.Invalidate(false);
                return(0);

            case MessageType.Paint:
                using (DeviceContext dc = window.BeginPaint())
                {
                    Windows.SetCursor(CursorId.Wait);
                    Windows.ShowCursor(true);

                    for (int i = 0; i < iCount - 1; i++)
                    {
                        for (int j = i + 1; j < iCount; j++)
                        {
                            dc.MoveTo(pt[i]);
                            dc.LineTo(pt[j]);
                        }
                    }

                    Windows.ShowCursor(false);
                    Windows.SetCursor(CursorId.Arrow);
                }
                return(0);
            }

            return(base.WindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 21
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));
        }
Exemplo n.º 22
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.º 23
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
                case WindowMessage.Create:
                    window.SetTimer(ID_TIMER, 1000);
                    stPrevious = Windows.GetLocalTime();
                    return 0;
                case WindowMessage.Size:
                    cxClient = lParam.LowWord;
                    cyClient = lParam.HighWord;
                    return 0;
                case WindowMessage.Timer:
                    SYSTEMTIME st = Windows.GetLocalTime();
                    bool fChange = st.wHour != stPrevious.wHour ||
                        st.wMinute != stPrevious.wMinute;
                    using (DeviceContext dc = window.GetDeviceContext())
                    {
                        SetIsotropic(dc, cxClient, cyClient);
                        dc.SelectObject(StockPen.White);
                        DrawHands(dc, stPrevious, fChange);
                        dc.SelectObject(StockPen.Black);
                        DrawHands(dc, st, true);
                    }
                    stPrevious = st;
                    return 0;
                case WindowMessage.Paint:
                    using (DeviceContext dc = window.BeginPaint())
                    {
                        SetIsotropic(dc, cxClient, cyClient);
                        DrawClock(dc);
                        DrawHands(dc, stPrevious, true);
                    }
                    return 0;
                case WindowMessage.Destroy:
                    window.KillTimer(ID_TIMER);
                    Windows.PostQuitMessage(0);
                    return 0;
            }

            return Windows.DefaultWindowProcedure(window, message, wParam, lParam);
        }
Exemplo n.º 24
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.º 25
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                dcScreen = Windows.CreateDeviceContext("DISPLAY", null);
                window.SetTimer(ID_TIMER, 100);
                return(0);

            case WindowMessage.Timer:
                POINT pt = Windows.GetCursorPosition();
                cr = dcScreen.GetPixel(pt);
                // Not sure why the sample did this
                // dcScreen.SetPixel(pt, 0);
                if (cr != crLast)
                {
                    crLast = cr;
                    window.Invalidate(false);
                }
                return(0);

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

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 26
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Size:
                cxClient = lParam.LowWord;
                cyClient = lParam.HighWord;
                return(0);

            case WindowMessage.Paint:
                POINT[] apt = new POINT[10];
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SelectObject(StockBrush.Gray);
                    for (int i = 0; i < 10; i++)
                    {
                        apt[i].x = cxClient * aptFigure[i].x / 200;
                        apt[i].y = cyClient * aptFigure[i].y / 100;
                    }

                    dc.SetPolyFillMode(PolyFillMode.Alternate);
                    dc.Polygon(apt);

                    for (int i = 0; i < 10; i++)
                    {
                        apt[i].x += cxClient / 2;
                    }
                    dc.SetPolyFillMode(PolyFillMode.Winding);
                    dc.Polygon(apt);
                }

                return(0);

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 27
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                MultimediaMethods.PlaySound(PlaySoundAlias.SND_ALIAS_SYSTEMHAND, PlaySoundOptions.SND_ASYNC | PlaySoundOptions.SND_NODEFAULT);
                return(0);

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

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 28
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.º 29
0
        static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam)
        {
            switch (message)
            {
            case WindowMessage.Create:
                using (DeviceContext dc = window.GetDeviceContext())
                {
                    dc.GetTextMetrics(out TEXTMETRIC tm);
                    cxChar = tm.tmAveCharWidth;
                    cxCaps = ((tm.tmPitchAndFamily.PitchTypes & FontPitchTypes.VariablePitch) != 0 ? 3 : 2) * cxChar / 2;
                    cyChar = tm.tmHeight + tm.tmExternalLeading;
                }
                return(0);

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

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

            return(Windows.DefaultWindowProcedure(window, message, wParam, lParam));
        }
Exemplo n.º 30
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:
                Span <Point> apt = stackalloc Point[10];
                using (DeviceContext dc = window.BeginPaint())
                {
                    dc.SelectObject(StockBrush.Gray);
                    for (int i = 0; i < 10; i++)
                    {
                        apt[i].X = cxClient * aptFigure[i].X / 200;
                        apt[i].Y = cyClient * aptFigure[i].Y / 100;
                    }

                    dc.SetPolyFillMode(PolyFillMode.Alternate);
                    dc.Polygon(apt);

                    for (int i = 0; i < 10; i++)
                    {
                        apt[i].X += cxClient / 2;
                    }
                    dc.SetPolyFillMode(PolyFillMode.Winding);
                    dc.Polygon(apt);
                }

                return(0);
            }

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