예제 #1
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)));
                    }
                }