How do you set hotspot co-ordinates on a Windows cursor generated from an icon file?
08:16 25 Jan 2010

I'm setting a custom cursor on my app from an icon file, but the click point is at the wrong co-ordinates. I'm setting the cursor with

SetClassLongPtr(hwnd, GCL_HCURSOR, reinterpret_castcursor)

where cursor is the result of

LoadImage(
    NULL,
    "some_path/cursor.ico", 
    IMAGE_ICON, //also tried IMAGE_CURSOR
    0, //width. 0 uses the width of the file provided
    0, //height. 0 uses the height of the file provided
    LR_LOADFROMFILE
); 

The cursor loads fine, but its clicks come from the bottom-left corner of the cursor image, rather than top-left.

The wikipedia article on .ico files says the hotspots are only specified on .cur files, not .ico.


ref: LoadImage() and SetClassLongPtr() on msdn.

winapi icons mouse-cursor