Archived

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

How to change the cursor of application.

This topic is 5337 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 wrote a DirectDraw program with Win32 API.Now, I want to change the cursor of application.I have created the cursor resource with ID: IDC_CURSOR,and I have made some changes during registering class,like the following: ...... wc.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_CURSOR)); ...... RegisterClass(&wc); However,the cursor of application still remains the same like before.Please provide some suggestion for me.Thanks!

Share this post


Link to post
Share on other sites
Just a thought, I could be wrong, but IDC_CURSOR could be the default cursor, perhaps if you rename your resource to something like IDC_MYSPECIALCURSOR or whatever rather than plain old IDC_CURSOR, it might work then.

Also I would suggest not including the NULL change:

wc.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_CURSOR));

to

wc.hCursor = LoadCursor(MAKEINTRESOURCE(IDC_CURSOR));

including the null suggests to me that you are loading a cursor from the resource with the name "", which obviously doesn''t exist!!

Also according to the help files:

Return Value

Nonzero if successful; otherwise zero.

Check your return values!! It would sure help to know if your function call was successful or not.

so in the end you should be using:

if((wc.hCursor = LoadCursor(MAKEINTRESOURCE(IDC_MYSPECIALCURSOR))) == 0)
return FALSE;

I think one of those things should sort your problem.

Share this post


Link to post
Share on other sites
quote:
Original post by Mephs
Also I would suggest not including the NULL change:

wc.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_CURSOR));

to

wc.hCursor = LoadCursor(MAKEINTRESOURCE(IDC_CURSOR));



I don''t think you can just eliminate the NULL... you have to replace the NULL with your application instance (hInstance), or if you don''t have that stored in an accessible variable, you can use GetModuleHandle(NULL) or something, but I assume you do, since you generally need it for the wc. so:

wc.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_CURSOR));

Share this post


Link to post
Share on other sites
Sorry, yes that is correct I was looking at the CWnd derived version of the function. Perhaps you should try obtaining a hInstance of your application using AfxGetInstanceHandle()? I wouldn''t be sure if specifiying null for the hInst would stop it working or not, but it''s worth a shot.

Share this post


Link to post
Share on other sites
If you pass NULL, you get the system default cursor for the ID you specify. Otherwise it checks the IDs you have within your application.

Share this post


Link to post
Share on other sites
Sorry to jump in here, but currently at the moment I havent hid the windows cursor and am just using that. Is there a performance reason for hiding it and replacing it with a custom drawn image besides the advantage of easily displaying your own cursors??

Share this post


Link to post
Share on other sites
I doubt there''s a performance reason, but I think the point of it, is:

a) it''s easy and quick
b) your cursor can be any size you like instead of a standard size
c) if you initialise your mouse position variables to start at 0,0 you can ensure the cursor starts there using a textured quad, the standard cursor doesn''t start at an arbitrary position and would require that you do something such as responding to the WM_MOUSEMOVE event to obtain the initial cursor position.

Perhaps there''s other reasons I''m missing aswell, but those would be my first thoughts.

Share this post


Link to post
Share on other sites
Thanks everyone!However I still couldn''t made the cursor the one I wanted by the method "wc.hCursor = LoadCursor(NULL,MAKEINTRESOURCE(IDC_CURSOR))" or "wc.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR))"

And I found AfxGetInstanceHandle( ) couldn''t be compiled for the reason of "undeclared identifier".

Share this post


Link to post
Share on other sites