Solved

Changing cursor.

Posted on 1998-09-24
13
811 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
[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
  • 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
Industry Leaders: 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 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

690 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