title: C# - Capturing the Mouse cursor image
body: <h2>BACKGROUND</h2>
  
  <ul>
  <li>I am writing a screen capture application</li>
  <li>My code is based derived from this project: <a href="http://www.codeproject.com/KB/cs/DesktopCaptureWithMouse.aspx?display=Print" rel="noreferrer">http://www.codeproject.com/KB/cs/DesktopCaptureWithMouse.aspx?display=Print</a></li>
  <li>Note that the code captures the the mouse cursor also (which is desirable for me)</li>
  </ul>
  
  <h2>MY PROBLEM</h2>
  
  <ul>
  <li>Code works fine when the mouse cursor is the normal pointer or hand icon - the mouse is rendered correctly on the screenshot</li>
  <li>However, when the mouse cursor is changed to the insertion point (the "I-beam" cursor) - for example typing in NOTEPAD - then code doesn't work - the result is that I get a faint image of the cursor - like a very translucent (gray) version of it instead of the blank &amp; white one would expect.</li>
  </ul>
  
  <h2>MY QUESTION</h2>
  
  <ul>
  <li>How can I capture the mouse cursor image when the image is one of these "I-beam"-type images</li>
  <li>NOTE: If you click on the original article someone offers a suggestion - it doesn't work</li>
  </ul>
  
  <h2>SOURCE</h2>
  
  <p>This is from the original article. </p>
  
  <pre><code>    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;
      }
  </code></pre>