Example #1
0
        void DrawClock(DeviceContext dc)
        {
            int iAngle;
            Point[] pt = new Point[3];

#if GDIPLUS
            using (var graphics = GdiPlusMethods.CreateGraphics(dc))
            using (var brush = GdiPlusMethods.CreateSolidBrush(Color.Black))
            {
                GdiPlusMethods.SetSmoothingMode(graphics, SmoothingMode.AntiAlias);
#else
                dc.SelectObject(StockBrush.Black);
#endif
                for (iAngle = 0; iAngle < 360; iAngle += 6)
                {
                    pt[0].X = 0;
                    pt[0].Y = 900;
                    RotatePoint(pt, 1, iAngle);
                    pt[2].X = pt[2].Y = iAngle % 5 != 0 ? 33 : 100;
                    pt[0].X -= pt[2].X / 2;
                    pt[0].Y -= pt[2].Y / 2;
                    pt[1].X = pt[0].X + pt[2].X;
                    pt[1].Y = pt[0].Y + pt[2].Y;

#if GDIPLUS
                    GdiPlusMethods.FillEllipse(graphics, brush, pt[0].X, pt[0].Y, pt[1].X - pt[0].X, pt[1].Y - pt[0].Y);
#else
                    dc.Ellipse(Rectangle.FromLTRB(pt[0].X, pt[0].Y, pt[1].X, pt[1].Y));
#endif
                }
#if GDIPLUS
            }
#endif
        }
Example #2
0
        static void DrawClock(DeviceContext dc)
        {
            int iAngle;
            POINT[] pt = new POINT[3];

#if GDIPLUS
            using (var graphics = GdiPlusMethods.CreateGraphics(dc))
            using (var brush = GdiPlusMethods.CreateSolidBrush(new ARGB(0, 0, 0)))
            {
                GdiPlusMethods.SetSmoothingMode(graphics, SmoothingMode.AntiAlias);
#else
                dc.SelectObject(StockBrush.Black);
#endif
                for (iAngle = 0; iAngle < 360; iAngle += 6)
                {
                    pt[0].x = 0;
                    pt[0].y = 900;
                    RotatePoint(pt, 1, iAngle);
                    pt[2].x = pt[2].y = iAngle % 5 != 0 ? 33 : 100;
                    pt[0].x -= pt[2].x / 2;
                    pt[0].y -= pt[2].y / 2;
                    pt[1].x = pt[0].x + pt[2].x;
                    pt[1].y = pt[0].y + pt[2].y;

#if GDIPLUS
                    GdiPlusMethods.FillEllipse(graphics, brush, pt[0].x, pt[0].y, pt[1].x - pt[0].x, pt[1].y - pt[0].y);
#else
                    dc.Ellipse(pt[0].x, pt[0].y, pt[1].x, pt[1].y);
#endif
                }
#if GDIPLUS
            }
#endif
        }
Example #3
0
        static void Main()
        {
#if GDIPLUS
            UIntPtr token = GdiPlusMethods.Startup();
#endif

            Windows.CreateMainWindowAndRun(new Clock(), "Analog Clock");

#if GDIPLUS
            GdiPlusMethods.Shutdown(token);
#endif
        }
Example #4
0
        static void DrawHands(DeviceContext dc, SYSTEMTIME pst, bool fChange)
        {
            int[] iAngle =
            {
                (pst.wHour * 30) % 360 + pst.wMinute / 2,
                pst.wMinute * 6,
                pst.wSecond * 6
            };

            POINT[][] pt =
            {
                new POINT[] { new POINT(0, -150), new POINT(100, 0), new POINT(0, 600), new POINT(-100, 0), new POINT(0, -150) },
                new POINT[] { new POINT(0, -200), new POINT(50, 0), new POINT(0, 800), new POINT(-50, 0), new POINT(0, -200), },
                new POINT[] { new POINT(0, 0), new POINT(0, 0), new POINT(0, 0), new POINT(0, 0), new POINT(0, 800) }
            };

            COLORREF color = GdiMethods.GetPenColor(dc.GetCurrentPen());
            bool erase = (color != new COLORREF());

#if GDIPLUS
            using (var graphics = GdiPlusMethods.CreateGraphics(dc))
            {
                if (erase)
                {
                    using (var brush = GdiPlusMethods.CreateSolidBrush(color))
                    {
                        GdiPlusMethods.FillEllipse(graphics, brush, -830, -830, 1660, 1660);
                    }
                    return;
                }

                using (var pen = GdiPlusMethods.CreatePen(color))
                {
                    GdiPlusMethods.SetSmoothingMode(graphics, SmoothingMode.HighQuality);

#endif

                    for (int i = fChange ? 0 : 2; i < 3; i++)
                    {
                        RotatePoint(pt[i], 5, iAngle[i]);

#if GDIPLUS
                        GdiPlusMethods.DrawLines(graphics, pen, pt[i]);
#else
                        dc.Polyline(pt[i]);
#endif
                    }
#if GDIPLUS
                }
            }
#endif
        }
Example #5
0
        static void Main()
        {
#if GDIPLUS
            UIntPtr token = GdiPlusMethods.Startup();
#endif
            const string szAppName = "Clock";

            ModuleInstance module = Marshal.GetHINSTANCE(typeof(Program).Module);
            WindowClass wndclass = new WindowClass
            {
                Style = ClassStyle.HorizontalRedraw | ClassStyle.VerticalRedraw,
                WindowProcedure = WindowProcedure,
                Instance = module,
                Icon = IconId.Application,
                Cursor = CursorId.Arrow,
                Background = StockBrush.White,
                ClassName = szAppName
            };

            Windows.RegisterClass(ref wndclass);

            WindowHandle window = Windows.CreateWindow(
                module,
                szAppName,
                "Analog Clock",
                WindowStyles.OverlappedWindow);

            window.ShowWindow(ShowWindow.Normal);
            window.UpdateWindow();

            while (Windows.GetMessage(out MSG message))
            {
                Windows.TranslateMessage(ref message);
                Windows.DispatchMessage(ref message);
            }

#if GDIPLUS
            GdiPlusMethods.Shutdown(token);
#endif
        }