Archived

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

samosa

custom mouse cursor

Recommended Posts

samosa    122
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
Sarlok    122
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
utwo007    122
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.

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

Share this post


Link to post
Share on other sites