Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to change cursor in c++ and keep it ?

Posted on 2010-08-18
10
Medium Priority
?
1,642 Views
Last Modified: 2013-11-20
Hello, I would like the cursor (under windows) to be a personal one (.cur) , I done that:
		case WM_SETCURSOR:
 			SetCursor(hCursor);
			return 1;

Open in new window

And it works but this way the cursor change again when roll over the window, is there a wait to keep it ?

Thanks
0
Comment
Question by:Greg2FS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 3
10 Comments
 
LVL 9

Expert Comment

by:JohnGaby
ID: 33465465
What does this not do that you need?
0
 
LVL 1

Author Comment

by:Greg2FS
ID: 33465691
Sorry I write a wrong thing, the problem is when the cursor roll out (not over) I would like it to stay my cursor.
0
 
LVL 9

Accepted Solution

by:
JohnGaby earned 1000 total points
ID: 33465864
So you want to set the cursor system wide?  Have you tried SetSystemCursor:

http://msdn.microsoft.com/en-us/library/ms648395%28VS.85%29.aspx
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 7

Expert Comment

by:HalfAsleep
ID: 33466953
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


0
 
LVL 1

Author Comment

by:Greg2FS
ID: 33468366
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 ?
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 33469086
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.
0
 
LVL 9

Expert Comment

by:JohnGaby
ID: 33470049
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
0
 
LVL 1

Author Comment

by:Greg2FS
ID: 33471068
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.
0
 
LVL 7

Expert Comment

by:HalfAsleep
ID: 33472516
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.

0
 
LVL 1

Author Closing Comment

by:Greg2FS
ID: 33540662
Not an exact solution but maybe the only one.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question