Solved

Changing cursor.

Posted on 1998-09-24
13
776 Views
Last Modified: 2008-02-20
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?
0
Comment
Question by:dst
  • 6
  • 4
  • 3
13 Comments
 

Author Comment

by:dst
ID: 1173705
Edited text of question
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1173706
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173707
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
 
LVL 2

Expert Comment

by:gysbert1
ID: 1173708
Not that much different from what I suggested ;o(
0
 
LVL 22

Expert Comment

by:nietod
ID: 1173709
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
 
LVL 2

Expert Comment

by:gysbert1
ID: 1173710
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 1173711
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
 

Author Comment

by:dst
ID: 1173712
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173713
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
 

Author Comment

by:dst
ID: 1173714
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
 
LVL 22

Accepted Solution

by:
nietod earned 100 total points
ID: 1173715
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
 
LVL 22

Expert Comment

by:nietod
ID: 1173716
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
 

Author Comment

by:dst
ID: 1173717
YES !!!!!!!!!!!!
I finaly got it to work...

   THANKS !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

912 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now