C# 如何找到父级非托管 win32 应用程序的子级
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1019790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find a child of a parent unmanaged win32 app
提问by Joan Venge
Basically I am looking for a win32 method to invoke in C# to set the focus to a children of an unmanaged application.
基本上,我正在寻找一种在 C# 中调用的 win32 方法,以将焦点设置为非托管应用程序的子级。
But first I need to find the child control's handle which is the problem. Any useful win32 functions to solve this?
但首先我需要找到问题所在的子控件的句柄。任何有用的 win32 函数来解决这个问题?
采纳答案by mihi
There is a library which supports enumerating and searching window handles, which is available at http://mwinapi.sourceforge.net/
有一个支持枚举和搜索窗口句柄的库,可在http://mwinapi.sourceforge.net/ 获得
Just so that you do not have to reinvent the wheel every time ;)
只是这样您就不必每次都重新发明轮子;)
Start with
从...开始
SystemWindow.AllToplevelWindows
and then just dig your way down (looking at class names, process names, titles, dialog IDs, whatever).
然后继续往下挖掘(查看类名、进程名、标题、对话框 ID 等等)。
回答by luiscubal
Have you tried to use FindWindowEx?
您是否尝试过使用 FindWindowEx?
回答by BFree
Use FindWindowExto find the Handle of the Window you're looking for. Once you have that handle, use EnumChildWindowsto find the correct child you need. There's too much code involved for me to quickly write up a sample, but there's enough on the web to help.
使用FindWindowEx查找您要查找的窗口的句柄。获得该句柄后,请使用EnumChildWindows查找所需的正确子级。涉及的代码太多,我无法快速编写示例,但网络上有足够的帮助。
From Pinvoke.net: http://www.pinvoke.net/default.aspx/user32/EnumChildWindows.html
从Pinvoke.net:http://www.pinvoke.net/default.aspx/user32/EnumChildWindows.html