Take the 2-minute tour ×

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_cast<LONG_PTR>cursor)

where cursor is the result of;

    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

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.

Edit: Clarified question

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

share|improve this question
Creating a .cur file from the .ico (or rather, the same bitmap the .ico was created from) and loading that fixes the problem. I would prefer not to have to fire up another application to do the conversion though. The ico file works as a cursor, just with the wrong co-ordinates. Surely there's a way to fix that. –  RJFalconer Jan 25 '10 at 15:29
add comment

3 Answers

up vote 3 down vote accepted

You can do this with CreateIconFromResourceEx

You pass in a pointer to a CURSOR_RES_HDR as the first parameter. This is one of those structures that you can find buried in the documentation, but it isn't any header file I can find. It's pretty simple though, basically to 16 bit unsigned ints followed by a BITMAPINFOHEADER containing the cursor image data.

typedef struct {
   WORD             xHot;         // x hotspot
   WORD             yHot;         // y hotspot



// Fill out pImage

HCURSOR hcur = CreateIconFromREsourceEx((BYTE*)pImage, 
                  cbImage, // size of image data + hotspot (in bytes)
                  0x00030000, // version: value mandated by windows
                  0, 0,       // width & height, 0 means use default
share|improve this answer
+1. Awesome, ty. –  RJFalconer Jan 26 '10 at 11:31
add comment

Use this excellent cursor editor for creating cursors and you can set the hotspot, make it animated, etc. I found it quite nifty and neat.

Hope this helps, Best regards, Tom.

share|improve this answer
+1, very handy. If only Gimp had an icon/cursor i/o plugin. –  RJFalconer Sep 13 '10 at 14:46
add comment

Yes, the hotspot is determined by the content of the .cur file. The Wikipedia article shows you this, offsets 4 and 6. Windows doesn't have an API to change the hotspot after the cursor is loaded. Simply edit the cursor in Visual Studio or any other cursor editor, specify the hot spot and save the file as a .cur file.

share|improve this answer
That's only the case for .cur files. LoadImage() allows cursors generated from bitmaps and icons. How do you specify hotspot then? –  RJFalconer Jan 25 '10 at 15:59
add comment

Your Answer


