如何在给定 HWND 的情况下获取窗口的子窗口?
我有给定窗口的句柄。我如何枚举它的子窗口?
I have the handle for a given window. How can I enumerate its child windows?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有给定窗口的句柄。我如何枚举它的子窗口?
I have the handle for a given window. How can I enumerate its child windows?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
这里您有一个可行的解决方案:
食用方法:
Here you have a working solution:
How to consume it:
使用:
您将获得传入函数的回调。
Using:
you will get callbacks on the function you pass in.
我发现最好的解决方案是托管 WindowsAPI。它有一个 CrossHair 控件,可用于选择一个窗口(不是问题的一部分),以及一个 AllChildWindows 方法,用于获取可能包装 EnumChildWindows 函数的所有子窗口。最好不要重新发明轮子。
I've found the best solution to be Managed WindowsAPI. It had a CrossHair control that could be used to select a window(not part of the question), and a method AllChildWindows to get all child windows which likely wrapped the EnumChildWindows function. Better not to reinvent the wheel.
使用 EnumChildWindows 和 p/invoke。这里有一个关于它的一些行为的有趣链接: https://blogs .msdn.microsoft.com/oldnewthing/20070116-04/?p=28393
如果您不知道窗口的句柄,而只知道它的标题,则需要使用 EnumWindows。 http://pinvoke.net/default.aspx/user32/EnumWindows.html
Use EnumChildWindows, with p/invoke. Here's an interesting link about some of it's behavior: https://blogs.msdn.microsoft.com/oldnewthing/20070116-04/?p=28393
If you don't know the handle of the window, but only it's title, you'll need to use EnumWindows. http://pinvoke.net/default.aspx/user32/EnumWindows.html
这是 EnumWindows 的托管替代方案,但您仍然需要使用 EnumChildWindows 查找子窗口的句柄。
Here is a managed alternative to EnumWindows, but you will still need to use EnumChildWindows to find the handle of the child window.