tags:

views:

356

answers:

4

I am curious how spy++ Finder Tool finds out the window handle for the window over which the mouse is. Is there any WIN32 function for getting the handle of the topmost window that occupies a certain pixel on the display?

+7  A: 

There is a WindowFromPoint() function.

Zed
since that returns a `HWND`, would `WindowFromPoint` work with windows from another process?
Evan Teran
HWNDs are valid throughout the whole OS, so yes.
DeusAduro
thanks, that's what i was looking for.I used something like this before: HWND wnd = (HWND)0x....; SendMessage(wnd,...); and it worked fine(it was a window for another application), so i think it works with that handle too. :)
Razvi
A: 

Don't quote me on it, but I believe spy++ would install a WH_CALLWNDPROC hook. This then gets sent all the WM_MOUSEMOVE messages before they reach their target windows. Thus as soon as you mouse over a window, spy++ recieves a message telling it which window.

DeusAduro
+1  A: 

WindowFromPoint or ChildWindowFromPoint API functions.

Richard
+4  A: 

Here is a pretty complete example of how to implement the spy++ finder.

http://www.codeproject.com/KB/dialog/windowfinder.aspx

sylvanaar