如何获取列表或枚举具有相同类和名称的非托管窗口的所有句柄
使用 pinvoke 我可以找到具有特定类和窗口的句柄轻松命名:
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = FindWindow("Foo Class", "Foo Window");
如果只有 0 或 1 个匹配窗口,则上述代码可以完美运行。然而,我正在使用的非托管应用程序跨越多个窗口。多次调用 FindWindow 每次都会返回相同的窗口句柄。
我需要做什么才能获取具有特定类和名称的所有窗口。
我也将接受相同目标的替代解决方案的答案。 (我想也许可以通过查找应用程序的进程ID,然后获取所有顶级窗口,并过滤所需的窗口来完成)。
Using pinvoke I can find Handle of a window with particular class & name easily:
[DllImport("user32.dll")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
IntPtr hWnd = FindWindow("Foo Class", "Foo Window");
The above code works perfect if there is only 0 or 1 matching windows. However the unmanaged application I am working with spans multiple windows. Calling FindWindow multiple times returns the same Window Handle each time.
What do I need to do to get ALL windows with particular class and name.
I will also accept answer for alternate solution the same goal. (I am thinking maybe it can be done by finding process ID of application and then getting all top level windows, and filtering for the ones needed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要调用 EnumWindows 来枚举所有顶层窗口。您必须使用它们的窗口句柄来获取它们的标题和窗口类信息。
请参阅http://www.pinvoke.net/default.aspx/user32/enumwindows。 html 的示例非常接近您所要求的内容。
You probably need to call EnumWindows to enumerate ALL top-level windows. You'll have to use their window handles to get their titles and window class information.
See http://www.pinvoke.net/default.aspx/user32/enumwindows.html for an example that does very close to what you're asking.