Constant cursor change

I am trying to change the cursor to some other cursor.

When I do this, all I get is a new cursor until I move the cursor again.

case WM_RBUTTONDOWN: cursor = LoadCursor (NULL, IDC_CROSS) ; SetCursor(cursor); break; 

How can I change it so that it is permanent. I know this has something to do with wndclass.

When I create a window in wndproc, I said wndclass.hIcon for IDC_ARROW, but I cannot call wndclass in WM_RBUTTONDOWN ..

Any help?

+4
source share
3 answers

Each mouse movement causes a WM_SETCURSOR message to be sent to your window; the default window procedure will respond with the configured cursor. Instead, return the new cursor.

+4
source

From the documentation for SetCursor :

If your application needs to position the cursor when it is in the window, make sure that the class cursor for the specified window class is NULL. If the class cursor is not NULL, the system restores the class cursor every time the mouse moves.

You need to remove any specified cursor from your window class.

+3
source

(I do not have enough reputation to comment)

Maybe I'm missing something, but the existing solutions do not work for me (redefining the implementation of WM_SETCUROSR violates the default cursor behavior when resizing the window, etc., Setting the default cursor to NULL does not seem to work for me, until calling SetCursor I get stuck when loading or resizing cursors.)

Here's a simple alternative solution, error handling for short. In my window initialization code, I set the default cursor to IDC_ARROW :

 global_window_class.hCursor = LoadCursor(NULL, IDC_ARROW); 

And then in my installed cursor function:

 // Get a handle to the cursor HCURSOR handle = LoadCursor(NULL, name); // Set the current cursor SetCursor(handle); // Modify the window class so that on move when the cursor resets, it just resets back to the one we want SetClassLongPtr(global_context->window, GCLP_HCURSOR, (LONG_PTR)handle); 
0
source

All Articles