Sign in to follow this  
Ripiz

Hardware cursor, how?

Recommended Posts

Ripiz    539
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
majickthise    139
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.
http://msdn.microsoft.com/en-us/library/ms648393%28VS.85%29.aspx

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.
http://msdn.microsoft.com/en-us/library/ms646265%28VS.85%29.aspx

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).
http://msdn.microsoft.com/en-us/library/ms648396%28VS.85%29.aspx

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.
http://msdn.microsoft.com/en-us/library/ms646970%28v=VS.85%29.aspx

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.
http://tk11.sourceforge.net/0_2/

Share this post


Link to post
Share on other sites

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