Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Changing cursor.

Posted on 1998-09-24
13
Medium Priority
?
838 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

581 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