Jump to content
  • Advertisement


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


custom mouse cursor

This topic is 5975 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

hey, can anyone tell me how to add my own mouse curosor for a program? i leanrt how to add my own icon froma thread but i couldnt find one for creating your own mouse, thanks ,Matt -= kill one your a murderer, kill thousands your a conquerer =-

Share this post

Link to post
Share on other sites
I think you have to set it when declaring your window class...


windowclassname.hCursor = LoadCursor(NULL, IDC_ARROW);


Try that, but change IDC_ARROW to the pointer for an .ani in a resource object or something.
I''ve no idea if that''ll work, bt that''d be my guess.

"When you kill one, it is a tragedy. When you kill ten million, it is a statistic."
- Sarlok

Share this post

Link to post
Share on other sites
Kinda, just make sure that the first parameter is hInstance (or whatever you named it), and not NULL.

Do it like this:

Create a resource file

You need to first create a resource file. Your IDE should have a resource compiler with it. I use Bloodshed''s free Dev-C++, which has a resource compiler as part of the package. When using Dev-C++, just right-click on your project name and click on "Edit Resource." Then enter the following code:

100 CURSOR "c:\directory\filename.cur"

The first item (100) is an arbitrary number you choose to identify your cursor with. The word CURSOR indicates the type of resource to create. The last string is the filename of the cursor. After typing this into your resource file, click on "Build Resource" to compile the resource.

Then, go to your main *.cpp file, where you registered the windows class, and then make sure to use the following:

winclass.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(100));

Make sure that winclass is actually whatever you named your class, and that hinstance is whatever you named the application instance handle. Notice the number 100 as the MAKEINTRESOURCE() parameter. That''s what identifies your cursor.

When you have a lot of resources (cursors, icons, bitmaps, whatever), those numbers can get a bit confusing. I (as well as 99% of everyone else) prefer to define some constants for those numbers, like this:

#define MY_CURSOR 100

...and then writing my resource file like this:

MY_CURSOR CURSOR "C:\filename.cur"

...and finally, the window class like this:

winclass.hCursor = LoadCursor(hinstance, MAKEINTRESOURCE(MY_CURSOR));

It''s just much easier to identify them by a name, than by a number. Remember, you''ll want to include the #define in both the resource file and the main *.cpp file, so that both files know what the hell MY_CURSOR is. In fact, if you have more than one resource, you better create one header file that contains all of the #define''s and include it in both the resource and main *.cpp files.

If you have any more questions, check out www.winprog.org.

People get ready.
I''m ready to play.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!