Question : Save Cursor as Bitmap

How to save the current Windows moise pointer (cursor) as a bitmap during application run-time using VB.net or C#?

Answer : Save Cursor as Bitmap

static Bitmap CaptureCursor(ref int x, ref int y)
{
   Bitmap bmp;
   IntPtr hicon;
   Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO();
   Win32Stuff.ICONINFO icInfo;
   ci.cbSize = Marshal.SizeOf(ci);
   if(Win32Stuff.GetCursorInfo(out ci))
   {
       if (ci.flags == Win32Stuff.CURSOR_SHOWING)
       {
           hicon = Win32Stuff.CopyIcon(ci.hCursor);
           if(Win32Stuff.GetIconInfo(hicon, out icInfo))
           {
               x = ci.ptScreenPos.x - ((int)icInfo.xHotspot);
               y = ci.ptScreenPos.y - ((int)icInfo.yHotspot);
               Icon ic = Icon.FromHandle(hicon);
               bmp = ic.ToBitmap();

               return bmp;
           }
       }
   }
   return null;
}
Random Solutions  
 
programming4us programming4us