A C++ Windows application desires to annotate the cursor bitmap with a small colored icon which conveys context dependent information, i.e. while hovering specific items. User preferences are to be respected, thus the system cursor must be modified instead of using an application specific cursor.
If the modified bitmap exists a new cursor can be created by a CreateIconIndirect API call.
We can create the modified bitmap by pixel manipulation of the original cursor bitmap.
We have access to the
HCURSORhandle, e.g. by calling GetCursor (alternatives like LoadImage give similar results).By searching the internet I found a possible solutions for obtaining the original bitmap, here the problem arises:
We use GetIconInfo (or GetIconInfoExW) to retrieve its color
HBITMAPand use GetObject to retrieve the BITMAP.The returned bitmap always has the dimensions 32x32, regardless of the DPI or the user's cursor scaling settings.
An alternative is using DrawIconEx onto a memory DC, however it seems to crudely upscale the 32x32 raster image and has inaccurate transparency pixels. Incurring loss of quality by upscaling a small raster image is not an option!
How can we get the exact cursor bitmap which is drawn onto the screen?
GetDpiForWindowto get the dpi value for the specified window. And then you could useLoadImageto load the bitmap. Bitmaps can be scaled manually usingStretchBlt. If you want to resize the bitmap dynamically when the dpi changes, you'll need to handleWM_DPICHANGED message.