Creating new cursor in VS2005

Started by
3 comments, last by Aiea 16 years, 4 months ago
Aloha people, I am starting to learn windows programming and trying to make a windows based tetris game. After reading about making custom mouse cursors I decided to give it a try, however it's not as easy as I thought. I created a really simple cursor and created the .cur file, but don't know how to include it in my main.cpp. Can anyone help?? Mahalo Aiea
Mahalo,AieaLove them semicolons and equal signs...
Advertisement
If you want to load the cursor from file at run time, you need to write something like:

HCURSOR hCursor = LoadCursorFromFile( "CursorFile.cur" );if( hCursor == NULL )    return false; // Failure.HCURSOR oldCursor = SetCursor( hCursor );



If you want to embed the cursor into the exe as a resource, you will need a resource editor. The Express version of VC++ 2005 doesn't have a resource editor, so if you're using that, you need a 3rd party resource editor. Once the cursor is embedded into the exe, you need to change the LoadCursorFromFile() call into LoadCursor( GetModuleHandle(0), MAKEINTRESOURCE( CURSOR_ID ) );

If you have more questions don't hesitate to ask. Cheers.
I have the full version of vs2005 and I used it to create my cursor file. The problem for me is to actually add the cursor into my source code. I have created the resource but can't seem to create an ID for it. Correct me if I'm wrong but I think I would need that for LoadCursor() to refer to.

Right now I have newCur.cur in my resource file folder and that's where I'm stuck =
Aiea
Mahalo,AieaLove them semicolons and equal signs...
Using the resource editor to create the cursor itself isn't really the best option - using a third party cursor creator/editor will probably help you make decent cursors, but that's not the point. Now, there should be a file in your project called resource.h. This file contains the IDs for all the resources that are included in the project. When you build the project, VC++ will embed the cursor and other resources into the exe. Your main.cpp should have an include statement for resource.h, and then you can use the ID for the cursor with LoadCursor(). Typically the id will be something like IDC_CURSOR1 or something.

You can find more info in the documentation for the platform SDK (User Interface>Windows User Interface>Resources>Cursors>Cursor Overview>Using Cursors.
After playing around with the resource.rc file I figured it out. I had to add the cursor there and I'd include it for me.

Thanks alot for the help =)

Aiea
Mahalo,AieaLove them semicolons and equal signs...

This topic is closed to new replies.

Advertisement