crumley
asked on
How do I find the control under the mouse?
How can I find the control under the mouse? I can't use WindowFromPoint or ChildWindowFromPoint if the window isn't active apparently. At least it doesn't give the right window handle. All I need to do, is get the handle of the control under the cursor. For example, Calculator in Windows. I want to be able to click...say, the "1" button. But I can't do this without having the control handle. I'd appreciate the code, but just the overview on how to do it would be great.
ASKER
thanks. I actually am going to use Delphi for this project...so I'll work on translating your code. Thanks for the answer!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
crumbley, you don't have to translate it, his code gets the handle and draws a rectangle around the control, which is according to your question not what you needed. The WindowFromPoint alone should do what you need just fine.
ASKER
@Freddy1990,
I've used WindowFromPoint/ChildWindo wFromPoint , and it doesn't work when the parent window is unfocused or slightly underneath an overlapping window. I may have been not implementing in correctly, so if you would give me some example code I would be happy to try.
I've used WindowFromPoint/ChildWindo
ASKER
you more or less helped lol...the links you gave me helped a lot more than the code really did. So thanks a lot!!!
I don't code in C++, but here is an example in VB.Net of a Timer getting the current window under the cursor with WindowFromPoint(), getting the rectangle of that window with GetWinddowRect(), and then drawing that rectangle on the screen.
When I move the mouse over Calculator I get a small rectangle over each button indicating that it is retrieving the handle for just that control:
(and no, Calculator was NOT in focus during the mouse over)
Open in new window