获取应用程序的窗口句柄句柄、应用程序、窗口

2023-09-02 21:10:36 作者:卑微の誓言

我要建,鉴于另一个应用程序mainWindowhandle它收集有关窗口状态信息的应用程序。我没有问题,收集有关的子窗口的信息,但我不能访问应用程序,甚至菜单的其他打开的窗口。有没有办法得到一个应用程序的所有窗口句柄?

I'm building an app that given another app mainWindowhandle it collects information about the window state. I have no problem collecting information about child windows, but I can not access the other open windows of an application or even the menus. Is there any way of getting all window handles of an application?

推荐答案

您可以做 Process.MainWindowHandle 似乎做什么:使用P / Invoke来调用 EnumWindows的 功能,调用回调方法,每顶-level窗口系统中的

You could do what Process.MainWindowHandle appears to do: use P/Invoke to call the EnumWindows function, which invokes a callback method for every top-level window in the system.

在你的回调,叫GetWindowThreadProcessId,和 Process.Id 比较窗口的进程ID;如果过程的ID匹配,则窗口句柄添加到列表。

In your callback, call GetWindowThreadProcessId, and compare the window's process id with Process.Id; if the process ids match, add the window handle to a list.