How does spy++ find out what is the window at a certain point on the screen?

二次信任 提交于 2019-12-06 00:59:48

问题


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?


回答1:


There is a WindowFromPoint() function.




回答2:


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

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




回答3:


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);



回答4:


WindowFromPoint or ChildWindowFromPoint API functions.




回答5:


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.



来源:https://stackoverflow.com/questions/1330074/how-does-spy-find-out-what-is-the-window-at-a-certain-point-on-the-screen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!