Sign in to follow this  

Creating new cursor in VS2005

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 3664 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this