Changing cursor.

Hi!
How do I change the cursor on the entire screen? (and not just on my window). I've tryed SetSystemCursor() but I have to be able to change it back to what it was before. Isn't there a simple way out of this?
dstAsked:
Who is Participating?
 
nietodCommented:
You're right it didn't change back.  I thought it did, but I was testing using an app that seems to be using its own arrow cursor.  The arrow cursor elsewhere never changed back.  The problem seems to be that GetIconInfo() is not working with any of the predefined constants (like IDC_ARROW).  The docs say it should work with these constants, but I can't get it to.  The solution is to use LoadCursor() with the ISC_ARROW constant (or any other) and get a handle to the cursor, then pass that handle to GetIconInfo().  When I do that it works fine.

0
 
dstAuthor Commented:
Edited text of question
0
 
gysbert1Commented:
What development platform are you using ?

The way to do this would be to save the active cursor before you change it and restore it again when you are done. You could use
   HCURSOR GetCursor(VOID);
to get the current cursor, then save its appearance for the restoration process.

I do not know a simpler way using the API but in VC or C++ builder you might gave a few other options ...
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
nietodCommented:
There is a way, but not an easy way.  (not too hard)  Use GetIconInfo() to get the bitmaps for the existing cursor.  Then change the cursor using SetSystemCursor().  Then create a new cursor using the information returned from GetIconInfo and restore the cursor using this new cursor and SetSystemCursor().

That's the best way I can see.
0
 
gysbert1Commented:
Not that much different from what I suggested ;o(
0
 
nietodCommented:
Agreed.  Your answer wasn't there when I got to the page (It took me a while to find the functions since I'm installing VC 6).  Otherwise I wouldn't have posted it as an answer.  You should have.
0
 
gysbert1Commented:
No problem, I am not that bothered about the points so you can have it this time if he gives it to you ;^). I was surprised cause I didn't expect you would do it on purpose ...
0
 
nietodCommented:
Right additude. These things happen.  If you let them bother you too much, you don't last here long.  Lots of experts burn out after a month or two because of this.  Let the little things slide and you'll earn the points in the long run.  (And you also learn a lot, which is even more rewarding.)
0
 
dstAuthor Commented:
Sorry, but I cant get it to work. It seems that the old cursor is destroyed when you set a new one. I've tryed both GetCursor() and GetIconInfo(). Here is what I do:

ICONINFO icoinf;
HCURSOR hNewCursor,hOldCursor;

GetIconInfo(IDC_ARROW,&icoinf);
hNewCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1));
SetSystemCursor(hNewCursor,OCR_NORMAL);

//-And then later

hOldCursor = CreateIconIndirect(&icoinf);
SetSystemCursor(hOldCursor,OCR_NORMAL);

It seems that the funktion fails with error 1813: ERROR_RESOURCE_TYPE_NOT_FOUND

What is wrong ? PLEASE HELP !!!
0
 
nietodCommented:
I just tested it and your code worked fine for me.  It changed the cursor and then back again.  I suspect your problem is that your cursor is not being loaded in line

hNewCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_CURSOR1));

check that that is not returning a NULL handle.  If it is, make sure that the cursor is being compiled and inserted into your application.

let me know if you need more.
0
 
dstAuthor Commented:
The problem is not the new cursor - it's when I shift back again I get the error. I can load the first cursor and set it as system cursor without problems - but when I want to set the old cursor as system cursor the SetSystemCursor() fails :-(

This is very odd...
0
 
nietodCommented:
By the way, make sure you eventually delete the bitmaps that are stored in the ICONINFO structure.  If you call, GetIconInfo(), that is your responsibility.
0
 
dstAuthor Commented:
YES !!!!!!!!!!!!
I finaly got it to work...

   THANKS !
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.