【发布时间】:2010-02-17 14:30:13
【问题描述】:
我需要捕获第 3 方进程的特定窗口。我可以找到主窗口句柄为 Process.MainWindowHandle,但我可以用什么来列出其他窗口?
我正在使用 C#/.NET
【问题讨论】:
我需要捕获第 3 方进程的特定窗口。我可以找到主窗口句柄为 Process.MainWindowHandle,但我可以用什么来列出其他窗口?
我正在使用 C#/.NET
【问题讨论】:
EnumChildWindows 函数可能会对您有所帮助。子窗口也可以有子窗口等等。
另一个帖子在这里有更多细节:Get handles to all windows of a process
【讨论】:
第 3 方应用程序启动了其他窗口而不是子窗口。
可以使用 Visual Studio 自带的 Spy++ 工具找出什么是结构。
在此之后,我能够使用 WindowClassName(取自 Spy++)使用 FindWindowEx 函数找到必要的窗口: lastWindows = FindWindowEx(IntPtr.Zero, lastWindows, m.WindowClassName, null);
【讨论】:
使用 Win32 API EnumWindows(如果你想要 EnumChildWindows)
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
然后通过Win32 APIGetWindowThreadProcessId检查每个窗口属于哪个进程
[DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
public static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);
【讨论】: