Greg2FS
asked on
How to change cursor in c++ and keep it ?
Hello, I would like the cursor (under windows) to be a personal one (.cur) , I done that:
Thanks
case WM_SETCURSOR:
SetCursor(hCursor);
return 1;
And it works but this way the cursor change again when roll over the window, is there a wait to keep it ?Thanks
What does this not do that you need?
ASKER
Sorry I write a wrong thing, the problem is when the cursor roll out (not over) I would like it to stay my cursor.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Be aware that setting the system cursor will set it for the entire windows OS, not just your application.
You must/should store the previous cursor(s) and reset back as you exit your application. So if your program crashes, your user is stuck with your program cursor.
It is often undesirable to play with the system cursors, just for this reason. Many users spend some efforts into finding the cursors/themes they like and get annoyed when their cursors get changed by some programs.
So if you decide to use System cursors, you should make every effort to make sure your program resets the cursors at exit.
This is the exact reason why SetCursor only sets for your application and as soon as you hover outside it or close your application, the cursor reverts to the system cursor.
In general, it is not recommended to use SetSystemCursor, but stay with application cursors instead.
Some of my own experiences with C# and .Net:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/dd01934b-7e3f-4e1a-9986-da99ec48e13e/#f8169276-0a0d-41de-b9a9-7ea3209e01b9
You must/should store the previous cursor(s) and reset back as you exit your application. So if your program crashes, your user is stuck with your program cursor.
It is often undesirable to play with the system cursors, just for this reason. Many users spend some efforts into finding the cursors/themes they like and get annoyed when their cursors get changed by some programs.
So if you decide to use System cursors, you should make every effort to make sure your program resets the cursors at exit.
This is the exact reason why SetCursor only sets for your application and as soon as you hover outside it or close your application, the cursor reverts to the system cursor.
In general, it is not recommended to use SetSystemCursor, but stay with application cursors instead.
Some of my own experiences with C# and .Net:
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/dd01934b-7e3f-4e1a-9986-da99ec48e13e/#f8169276-0a0d-41de-b9a9-7ea3209e01b9
ASKER
I really need to have my cursor even after a roll out... I imagine only a hook can avoid the "kill focus" to change the cursor ?
Why do you need the cursor to not change back to system cursor as you leave your window? That is the normal, expected behaviour. I cannot think of any other way of overriding this behaviour than using SetSystemCursor, but again, it really is not recommended.
Maybe you should consider if this really is something you actually need. I cannot think of a single reason for any of my applications to enforce its application cursors outside its own window.
Maybe you should consider if this really is something you actually need. I cannot think of a single reason for any of my applications to enforce its application cursors outside its own window.
Note that you can also call SetCapture to force all mouse messages to be redirected to your window. At some point, however, you will need to call ReleaseCapture, or people will not be able to click on any other application.
http://msdn.microsoft.com/en-us/library/ms646262%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms646262%28VS.85%29.aspx
ASKER
It seems than setcapture effectively capture mouse message outside the window but don't avoid cursor to change outside the window.
I can't tell you what I do exactly but imagine a billiards game in which the window is the table and we want the cursor to change to a cross to represent the end of the cue, of course it is outside the window.
About the setsystemcursor method I don't find how to store the previous cursor, I tried GetCursor but it doesn't work.
I can't tell you what I do exactly but imagine a billiards game in which the window is the table and we want the cursor to change to a cross to represent the end of the cue, of course it is outside the window.
About the setsystemcursor method I don't find how to store the previous cursor, I tried GetCursor but it doesn't work.
GetCursor will get you the handle. To make sure you have a valid copy that does not get freed by another module/OS etc. you can try to perform CopyCursor on the handle returned by GetCursor.
ASKER
Not an exact solution but maybe the only one.