How to change the cursor of application.

Started by
7 comments, last by winsoft2003 20 years, 11 months ago
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!
I am a Chinese spare time game developer and I hope to make mores friends to talk about game developing!
Advertisement
Hide your cursor and draw a quad/bitmap manually at the cursor position. That''s what most people do.

Sander Maréchal
[Lone Wolves GD][RoboBlast][Articles][GD Emporium][Webdesign][E-mail]

<hr />
Sander Marechal<small>[Lone Wolves][Hearts for GNOME][E-mail][Forum FAQ]</small>

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.
Cheers,SteveLiquidigital Online
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));
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.
Cheers,SteveLiquidigital Online
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.
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??
------------------------------------------------------
50% of me is a huge nerd! How about you?
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.
Cheers,SteveLiquidigital Online
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".
I am a Chinese spare time game developer and I hope to make mores friends to talk about game developing!

This topic is closed to new replies.

Advertisement