获取进程的所有窗口句柄
使用 Microsoft Spy++,我可以看到属于进程的以下窗口:
Process XYZ 窗口句柄,以树形式显示,就像 Spy++ 给我的:
A
B
C
D
E
F
G
H
I
J
K
我可以获取进程,并且 MainWindowHandle 属性指向窗口 F 的句柄。如果我使用枚举子窗口,我可以获得 G 到 K 的窗口句柄列表,但我不知道如何找到 A 到 D 的窗口句柄。如何枚举不是句柄子级的窗口由 Process 对象的 MainWindowHandle 指定?
枚举我正在使用 win32 调用:
[System.Runtime.InteropServices.DllImport(strUSER32DLL)]
public static extern int EnumChildWindows(IntPtr hWnd, WindowCallBack pEnumWindowCallback, int iLParam);
Using Microsoft Spy++, I can see that the following windows that belong to a process:
Process XYZ window handles, displayed in tree form just like Spy++ gives me:
A
B
C
D
E
F
G
H
I
J
K
I can get the process, and the MainWindowHandle property points to the handle for window F. If I enumerate the child windows using I can get a list of window handles for G through K, but I can't figure out how to find the window handles for A through D. How can I enumerate windows that are not children of the handle specified by MainWindowHandle of the Process object?
To enumerate I'm using the win32 call:
[System.Runtime.InteropServices.DllImport(strUSER32DLL)]
public static extern int EnumChildWindows(IntPtr hWnd, WindowCallBack pEnumWindowCallback, int iLParam);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将
IntPtr.Zero
作为hWnd
传递以获取系统中的每个根窗口句柄。然后,您可以通过调用 来检查 Windows 所有者进程
GetWindowThreadProcessId
。Pass
IntPtr.Zero
ashWnd
to get every root window handle in the system.You can then check the windows' owner process by calling
GetWindowThreadProcessId
.对于仍然想知道的每个人,这就是答案:
for WindowsInterop:
for WindowsInterop.User32:
现在可以通过 GetRootWindowsOfProcess 简单地获取每个根窗口,并通过 GetChildWindows 获取它们的子窗口。
For everyone still wondering, this is the answer:
for WindowsInterop:
for WindowsInterop.User32:
Now one can simply get every root window by GetRootWindowsOfProcess, and their children by GetChildWindows.
您可以使用
EnumWindows
获取每个顶级窗口,然后根据GetWindowThreadProcessId
。You can use
EnumWindows
to get every top-level window, and then filter the results based onGetWindowThreadProcessId
.