Solved

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

Posted on 2001-07-09
5
202 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
[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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…

738 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