Solved

Changing cursor.

Posted on 1998-09-24
13
771 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

20 Experts available now in Live!

Get 1:1 Help Now