Archived

This topic is now archived and is closed to further replies.

Windows SetCursor() problem

This topic is 5378 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m using MVC++ and Windows SDK I''m trying to use SetCursor() to change the cursor image while my program is running. I load a cursor from a resource into an HCURSOR handle and pass it to SetCursor(). The new cursor image shows up indeed, but it flashes overtop of the old arrow cursor that I loaded when initializing my windows class. Here''s the relevant part of my code:
  

//Initialize the window class

HWND hwnd;

WNDCLASS wndclass;
wndclass.lpfnWndProc = WindowProc;
wndclass.style = CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hinstance;
wndclass.hIcon = LoadIcon(hinstance,IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "MYWINCLASS";

//Register the window class

if(RegisterClass(&wndclass)==0) {
   ErrorMsg("Error registering window class",hwnd);
   return 0;
}

//Create the game window

hwnd = CreateWindow("MYWINCLASS","Orb Of Fish Window",WS_POPUP|WS_VISIBLE,0,0,640,480,NULL,NULL,hinstance,NULL);

//Show the cursor

ShowCursor(true);

////////////////

//

// 500 lines of irrevelent code later...

//

////////////////


//Load a new home-made cursor from a resource

HCURSOR cursor_new = LoadCursor(hinstance,MAKEINTRESOURCE(IDC_CURSOR1));
SetCursor(cursor_new);

  
Any thoughts?

Share this post


Link to post
Share on other sites
i think you have to overwrite the cursor handle in the wndclass with the new cursor handle. as far as i can remember, you''d have to use "SetClassLong" for this. this should help but i don''t know wether it is a hack or if it''s ok to do this!

Share this post


Link to post
Share on other sites
I personally would go with morebeer''s solution but if you want to use SetCursor() when the cursor enters the client area to change the cursor you will have to set the class cursor to NULL.

quote:
From MSDN, SetCursor()

If your application must set the cursor while it is in a window, make sure the class cursor for the specified window''s class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved.






Qui fut tout, et qui ne fut rien
Invader''s Realm

Share this post


Link to post
Share on other sites
quote:
[quote]
From MSDN, SetCursor()

If your application must set the cursor while it is in a window, make sure the class cursor for the specified window''s class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved.




Thanks a billion! The said restoration of the cursor every time the mouse is moved is EXACTLY my problem. Fixed.

Share this post


Link to post
Share on other sites