That being said, this updated CaptureCursor() method will handle both color and monochrome cursors, supplying a plain black cursor image when the cursor is monochrome.
CURSORS IMAGE WINDOWS
However, when the image is drawn over no background, as in your posted code, the raster operations that Windows performs result in a faded image. On the desktop, since the raster operations are applied over the desktop content, the cursor will appear correct. One of the comments for the original article that you linked mentions this. Onscreen, The cursor will appear as the inverse of the content behind it. The bottom half of the bitmap is then drawn over top with an XOR raster operation. When Windows draws the I-Beam cursor, the top half of this bitmap is first drawn over the desktop with an AND raster operation. The top half of the mask bitmap is the AND mask, and the bottom half of the mask bitmap is the XOR bitmap.
When you call GetIconInfo() for the I-Beam cursor, though, the ICONINFO struct only contains a valid mask bitmap, and no color bitmap, as shown below (Note: again, the red border has been added to clearly show the image boundaries):Īccording to the ICONINFO documentation, the I-Beam cursor is then a monochrome cursor. This results in an opaque cursor and a transparent background. When Windows draws the default cursor, the mask bitmap is first applied with an AND raster operation, then the color bitmap is applied with an XOR raster operation. When you call GetIconInfo() for the default cursor, the ICONINFO struct contains both valid mask and color bitmaps, as shown below (Note: the red border has been added to clearly show the image boundaries): The ICONINFO struct contains two members, hbmMask and hbmColor, that contain the mask and color bitmaps, respectively, for the cursor (see the MSDN page for ICONINFO for the official documentation).
CURSORS IMAGE HOW TO
While I can't explain exactly why this happens, I think I can show how to get around it. Y = ci.ptScreenPos.y - ((int)icInfo.yHotspot) X = ci.ptScreenPos.x - ((int)icInfo.xHotspot) If (Win32Stuff.GetIconInfo(hicon, out icInfo)) If (ci.flags = Win32Stuff.CURSOR_SHOWING) Win32Stuff.CURSORINFO ci = new Win32Stuff.CURSORINFO() static Bitmap CaptureCursor(ref int x, ref int y) NOTE: If you click on the original article someone offers a suggestion - it doesn't work.How can I capture the mouse cursor image when the image is one of these "I-beam"-type images.
CURSORS IMAGE CODE