问题
I want to create the same function "Find windows..." of spy++ in C#. I have try with this function of the WINAPI:
HWND WINAPI WindowFromPoint(__in POINT Point);
http://msdn.microsoft.com/en-US/library/ms633558.aspx But i don't arrive to get all element with that, because they are disabled or hidden.
For example with the window 7 calculator in Programmer mode, i cannot get the "A B C D E F" with my program if they are disable then spy++ can get it.
Edit: I have try this but it don't working:
[DllImport("user32.dll")]
public static extern ulong GetClassLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
public static extern IntPtr ChildWindowFromPointEx(IntPtr hWndParent, Win32Point pt, uint uFlags);
IntPtr hWnd = WindowFromPoint(myPoint);
hWnd= ChildWindowFromPointEx(hWnd , myPoint, 0x0000);
myPoint is the position of my mouse.
I don't familiar with the WINAPI and i imagine with your explanation that is a lack of understanding of me. It's possible to have a little example of ChildWindowFromPointEx function or know what my code don't working? thanx for your answer
I have try to create the loop but, it seems the handle is under the other handle but is not children of the handle, the loop send alway the same handle and no the desire child when the key " a b c d e f" is disabled. Do you have another idea?
回答1:
WindowFromPoint
returns a window handle. Since you are dealing with disabled/hidden windows, you would want to use ChildWindowFromPointEx, passing in hwndParent
as whatever handle you obtained from WindowFromPoint
.
You might find the following article helpful: http://blogs.msdn.com/b/oldnewthing/archive/2010/12/30/10110077.aspx
In regards to the code you added, ChildWindowFromPointEx
takes client coordinates, whereas the mouse position coordinates you have are screen coordinates. You can do the conversion with ScreenToClient.
Note: This is the WinAPI way to do things. I have no idea whether or what APIs C# supplies.
来源:https://stackoverflow.com/questions/9508514/create-the-function-find-window-of-spy-in-c-sharp