I need to capture particular windows of 3rd party process. I can find main window handle as Process.MainWindowHandle, but what I can use to list other开发者_高级运维 windows?
I am using C# / .NET
.NET (C#): Getting child windows when you only have a process handle or PID?
The EnumChildWindows function might help you out. The child windows could also have children and so on.
There is also GetWindow and EnumThreadWindows
Another post here with some more details: Get handles to all windows of a process
3rd party aplication launched other windows not as child windows.
It is possible to find out what is structure using Spy++ tool which comes with Visual Studio.
After this, I was able to find necessary window using FindWindowEx function using WindowClassName (taken from Spy++): lastWindows = FindWindowEx(IntPtr.Zero, lastWindows, m.WindowClassName, null);
Use the Win32 API EnumWindows (and if you want EnumChildWindows)
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
Then check which process each window belongs to by using the Win32 API GetWindowThreadProcessId
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
精彩评论