Question: 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?

Answer: 
There is a [WindowFromPoint()](http://msdn.microsoft.com/en-us/library/ms633558%28VS.85%29.aspx) function.
There is some nice information on the internals of Spy++ here: <http://blogs.msdn.com/b/vcblog/archive/2007/01/16/spy-internals.aspx>. It supports DeusAduro's reply, that Spy++ installs global hooks (actually 3 hooks, one of which is WH\_CALLWNDPROC).

You can also find some more info on a Spy++-clone here: <http://www.codeproject.com/KB/dialog/windowfinder.aspx>.

Also, there should be a download for a very similar app in the SDK here: <http://msdn.microsoft.com/en-us/library/Aa231779> but it seems to be broken (no download - like so many links on msdn :( ).

Depending on what you want to get (if it is not a hwnd) you can also get an AutomationElement:

```
System.Windows.Point pt = new System.Windows.Point(System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y);
AutomationElement ae = AutomationElement.FromPoint(pt);

```