?
Solved

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

Posted on 2001-07-09
5
Medium Priority
?
215 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 600 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

Independent Software Vendors: 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!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

801 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