Example #1
0
        private static void DrawCursorToBitmap(Bitmap windowImage, Point offsetLocation)
        {
            var ci = new CursorInfoStruct();

            ci.cbSize = Marshal.SizeOf(ci);
            if (WindowsApi.GetCursorInfo(out ci))
            {
                if (ci.flags == 1)
                {
                    IntPtr         hicon = WindowsApi.CopyIcon(ci.hCursor);
                    IconInfoStruct icInfo;
                    if (WindowsApi.GetIconInfo(hicon, out icInfo))
                    {
                        var    loc = new Point(ci.ptScreenPos.X - offsetLocation.X - icInfo.xHotspot, ci.ptScreenPos.Y - offsetLocation.Y - icInfo.yHotspot);
                        Icon   ic  = Icon.FromHandle(hicon);
                        Bitmap bmp = ic.ToBitmap();

                        Graphics g = Graphics.FromImage(windowImage);
                        g.DrawImage(bmp, new Rectangle(loc, bmp.Size));
                        g.Dispose();
                        WindowsApi.DestroyIcon(hicon);
                        bmp.Dispose();
                    }
                }
            }
        }
Example #2
0
 public static extern bool GetCursorInfo(out CursorInfoStruct pci);
Example #3
0
        private static void DrawCursorToBitmap(Bitmap windowImage,
                                               Point offsetLocation) {
            var ci = new CursorInfoStruct();
            ci.cbSize = Marshal.SizeOf(ci);
            if (WindowsApi.GetCursorInfo(out ci)) {
                if (ci.flags == 1) {
                    IntPtr hicon = WindowsApi.CopyIcon(ci.hCursor);
                    IconInfoStruct icInfo;
                    if (WindowsApi.GetIconInfo(hicon, out icInfo)) {
                        var loc =
                            new Point(
                                ci.ptScreenPos.X - offsetLocation.X -
                                icInfo.xHotspot,
                                ci.ptScreenPos.Y - offsetLocation.Y -
                                icInfo.yHotspot);
                        Icon ic = Icon.FromHandle(hicon);
                        Bitmap bmp = ic.ToBitmap();

                        Graphics g = Graphics.FromImage(windowImage);
                        g.DrawImage(bmp, new Rectangle(loc, bmp.Size));
                        g.Dispose();
                        WindowsApi.DestroyIcon(hicon);
                        bmp.Dispose();
                    }
                }
            }
        }
Example #4
0
 public static extern bool GetCursorInfo(out CursorInfoStruct pci);