Jump to content
  • Advertisement
Sign in to follow this  

Hardware cursor, how?

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

I would like to have custom mouse pointers in my.. project. I tried Google but failed to find. Maybe anyone could show me how to load and set mouse pointer icon, also hide and show mouse pointer in my project? I'm using C++, DirectX9. Preferably to work in both modes, window and fullscreen. I think it refers to Windows SDK/Window Class/Whatever it's called but I failed to find anything. Thank you in advance.

Share this post

Link to post
Share on other sites
When you register a window class for your application window, you can specify a class cursor in the WNDCLASSEX structure. If you specify 0, then the cursor will still be visible when it moves over your window, but it will have the appearance it had before it entered your window.

If you want to change the cursor appearance dynamically, then you can use SetCursor. However, this works only when yuo specify 0 as the class cursor in WNDCLASSEX. If you pass 0 to SetCursor, then the cursor will be hidden.

SetCursor is typically called in WM_MOUSEMOVE. It may be a good idea to call it only in the first WM_MOUSEMOVE event you get when the cursor enters your window. This requires that you get notified when the cursor exits the window (so you can reset a flag, which reenables the call to SetCursor in the next WM_MOUSEMVOE event). This can be done using TrackMouseEvent and WM_MOUSELEAVE. You do not need to reset the cursor it leaves your window. Other apps will take care of the cursor when it enters their windows.

If you only want to hide the cursor over your window, then the proper way is to set 0 as the class cursor, call SetCursor(0) in the "first" WM_MOUSEMOVE event and use TrackMouseEvent as I described above.

A quick and dirty way to hide and show the cursor is ShowCursor. However, it hides the cursor globally, and you have to call it repeatedly until the display counter reaches zero. I wouldn't recommend it, unless you are short on time (who isn't?;) and only interested in fullscreen mode (which you are not).

You will find more documentation about cursors here. This is where you should look if you want to know how to define custom cursor images.

Alternatively, you can render the cursor yourself using DX9 draw calls. Then you need to hide the regular Windows cursor.

If you need example code, you can have a look at the source code of my latest project. It is a toolkit library for DirectX 11, but the mouse cursor stuff should work with DX9 as well. Most of it can be found in window_impl.cpp. It doesn't create custom cursor images, but it shows how to show and hide the cursor.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!