Solved

A fun one:  TCursor, Screen.Cursors, and desktop capture

Posted on 2001-07-09
5
183 Views
Last Modified: 2010-05-18
Ok, I think this one may be kind of fun.  I've written a desktop magnification window... basicly just captures the desktop with getDC, resizes to some factor, pastes to an image and refreshes.. etc etc.

As you probably know getDC(0) just returns most everything on the screen EXCEPT the cursor. So I wrote some code that just kinda draws a black target on the image where the cursor would be, but thought it would be nice if I could show the actual current cursor (no matter what it is).. anyway, I started looking around and found that you can actually load in custom cursors.

So here are my questions:

1) I want to be able to get back the image of the current cursor... in say a bitmap, or something, so I can incorporate it into my zoom program.

2) I would like to see an example of loading a custom cursor into memory from a cursor file or bitmap (whatever) and maybe an explenation on how to use it, free it, and anything else you can think of.

3) Another question:  is there a way to get the images of CUSTOM cursors (I mean like the stuff CursorEx does; animation and stuff - think it might be achieved through ActiveX).

By the way, check out CursorEx, it's pretty cool.
http://www.ricciosoft.com/cursorex/
0
Comment
Question by:felonious
  • 3
  • 2
5 Comments
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Basically it's quite easy - you just need to call GetCursor, which will get you an icon handle. Then call GetIconInfo to get bitmap handles. Unfortunately the problem gets a bit more difficult now:
GetCursor works only for the current process. If the cursor is above a window that belongs to another process (e.g. the desktop), the cursor gets another shape, but GetCursor still returns the cursor which would be visible above YOUR window, which is very often a different one than it is really.
There are 2 tricks to make GetCursor work:
(1) Call GetCursorPos + WindowFromPoint to get the window above which the cursor currently is, then call GetWindowThreadProcessID to get the thread ID of the thread to which that window belongs. Then call AttachThreadInput to attach your thread to that thread. Now GetCursor works fine. Don't forget to detach the threads again. This solution has one big problem: Steadily attaching/detaching sometimes swallows double clicks.
(2) Use SetWindowsHookEx(WH_CALLWNDPROCRET) to install a system wide hook, put your callback function in a little dll and react on the WM_SETCURSOR message in that way that you send the new cursor from your dll to your application. That's no big problem if you know how to work with SetWindowsHookEx.

Regards, Madshi.
0
 

Author Comment

by:felonious
Comment Utility
Ok, sorry I took to long to get back to you.  I'm kind lost on some of the Windows SDK stuff.  Can you give me a GetCursor/GetIconInfo code example...  I dont need to get the cursor over any other application (just my own) so dont bother with that.

Thanks

-felonious
0
 
LVL 20

Accepted Solution

by:
Madshi earned 150 total points
Comment Utility
In that case it's much easier:

  DrawIconEx(Canvas.Handle, 10, 10, GetCursor, 0, 0, 0, 0, DI_NORMAL);

That's it!   :-)

Regards, Madshi.
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
P.S: For Canvas.Handle you can use any canvas handle, of course. And for "10, 10" give in the position where you want to mouse pointer to be drawn, could be e.g. the values from GetCursorPos.
0
 

Author Comment

by:felonious
Comment Utility
Works great!  Thanks for the help.

-felonious
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

12 Experts available now in Live!

Get 1:1 Help Now