static HWND btn;
HCURSOR cursor = LoadCursor(0, IDC_CROSS);
case WM_CREATE:
btn = CreateWindow(TEXT("BUTTON"), TEXT("Press Me"),
WS_CHILD|WS_VISIBLE, 50, 50, 80, 30,
hwnd, (HMENU) 111, NULL, NULL);
Now, in WM_COMMAND, I try to use:
SendMessage(btn, WM_SETCURSOR, 0, (LPARAM) cursor);
Which isn’t working.
So how do I change the cursor of the mouse after it clicks the button? Also, how do I change the cursor of the mouse as it is hovering over the button (like it changes to a hand when hovering over links in web-browsers)?
Use this code to change the cursor of a single control:
Preferred method, for 64 bit compatibility, is:
Note that this won’t change the icon only for the specified
btnwindow but for all windows with the same class, you have to first register a custom class name withRegisterClass()and then use it in theWNDCLASS.lpszClassNamestructure when creatingbtn.Again this will apply to all the Windows with that (custom) class. To change the cursor of a single specific window you need to subclass it, manage the
WM_SETCURSORmessage and if (for example)lParamisHTCLIENT(pointer entered the window client area) then callSetCursor()to set the cursor you want (don’t forget to returnTRUEin this case). Of course this might be temporary (callingSetWindowLongPtr()withGWLP_WNDPROC).