Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

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

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
felonious
Asked:
felonious
  • 3
  • 2
1 Solution
 
MadshiCommented:
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
 
feloniousAuthor Commented:
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
 
MadshiCommented:
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
 
MadshiCommented:
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
 
feloniousAuthor Commented:
Works great!  Thanks for the help.

-felonious
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now