Exemple #1
0
        private static void DrawCursor(IntPtr hCursor, Graphics graphics, Point location)
        {
            location.X += (int)graphics.Transform.OffsetX;
            location.Y += (int)graphics.Transform.OffsetY;

            User32Interop.ICONINFO iconInfo;
            if (!User32Interop.GetIconInfo(hCursor, out iconInfo))
            {
                return;
            }
            if (iconInfo.hbmColor != IntPtr.Zero)
            {
                Gdi32Interop.DeleteObject(iconInfo.hbmColor);
            }
            if (iconInfo.hbmMask != IntPtr.Zero)
            {
                Gdi32Interop.DeleteObject(iconInfo.hbmMask);
            }

            IntPtr hdc = graphics.GetHdc();

            try {
                int  x      = location.X - iconInfo.xHotspot;
                int  y      = location.Y - iconInfo.xHotspot;
                Size size   = GetCursorSize();
                int  width  = size.Width;
                int  height = size.Height;

                Gdi32Interop.IntersectClipRect(hdc, x, y, x + width, y + height);
                User32Interop.DrawIconEx(hdc, x, y, hCursor, width, height, 0, IntPtr.Zero, Gdi32Interop.DI_NORMAL);
            }
            finally {
                graphics.ReleaseHdcInternal(hdc);
            }
        }
Exemple #2
0
 public void Prepare(Graphics graphics)
 {
     if (!User32Interop.GetCursorPos(out this.cursorPos))
     {
         this.cursorPos = Point.Empty;
     }
 }
Exemple #3
0
        private static Size GetCursorSize()
        {
            int width  = User32Interop.GetSystemMetrics(User32Interop.SystemMetric.SM_CXCURSOR);
            int height = User32Interop.GetSystemMetrics(User32Interop.SystemMetric.SM_CYCURSOR);

            return(new Size(width, height));
        }
        private static Rectangle GetPrimaryScreenBounds()
        {
            int width  = User32Interop.GetSystemMetrics(User32Interop.SystemMetric.SM_CXSCREEN);
            int height = User32Interop.GetSystemMetrics(User32Interop.SystemMetric.SM_CYSCREEN);

            return(new Rectangle(0, 0, width, height));
        }
        private static Point GetCursorPos()
        {
            Point cursorPos;

            if (User32Interop.GetCursorPos(out cursorPos))
            {
                return(cursorPos);
            }
            return(Point.Empty);
        }
        private static int GetPrimaryScreenBitDepth()
        {
            int    bitDepth;
            IntPtr hdc = User32Interop.GetDC(IntPtr.Zero);

            try {
                bitDepth  = Gdi32Interop.GetDeviceCaps(hdc, Gdi32Interop.DeviceCap.BITSPIXEL);
                bitDepth *= Gdi32Interop.GetDeviceCaps(hdc, Gdi32Interop.DeviceCap.PLANES);
            }
            finally {
                User32Interop.ReleaseDC(IntPtr.Zero, hdc);
            }
            return(bitDepth);
        }
Exemple #7
0
        private static void DrawDefaultCursor(Graphics graphics, Point location)
        {
            IntPtr hCursor = User32Interop.LoadCursor(IntPtr.Zero, User32Interop.IDC_ARROW);

            try {
                DrawCursor(hCursor, graphics, location);
            }
            finally {
                if (hCursor != IntPtr.Zero)
                {
                    User32Interop.DestroyCursor(hCursor);
                }
            }
        }