Solved

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

Posted on 2001-07-09
5
193 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
ID: 6268053
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
ID: 6282680
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
ID: 6283230
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
ID: 6283233
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
ID: 6283791
Works great!  Thanks for the help.

-felonious
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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