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);
            }
        }
        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);
        }