【发布时间】:2013-04-18 06:09:55
【问题描述】:
我正在构建一个应用程序,它将获得所有控制权到应用程序 winform 正在运行。首先,我可以将 dll 注入到 winform 正在运行的应用程序中并获取应用程序 winform 正在运行的句柄。在我让所有子窗口进入应用程序之后。接下来,我想通过 FindWindowEx 将所有控件放入子窗口。但我不能
代码如下:
static ArrayList GetAllChildrenWindowHandles(IntPtr hParent, int maxCount)
{
ArrayList result = new ArrayList();
int ct = 0;
IntPtr prevChild = IntPtr.Zero;
IntPtr currChild = IntPtr.Zero;
while (true && ct < maxCount)
{
currChild = FindWindowEx(hParent, prevChild, null, null);
if (currChild == IntPtr.Zero)
{
int errorCode = Marshal.GetLastWin32Error();
break;
}
result.Add(currChild);
prevChild = currChild;
++ct;
}
return result;
}
我得到一个子窗口的句柄并使用它作为父窗口。但是我无法通过 FindWindowEx 将所有控制权都控制到子窗口中。 对不起我的英语
【问题讨论】:
-
如果您要查找某个特定窗口的所有子窗口,您需要
EnumChildWindows。 -
逻辑结构是一棵树。最容易用递归函数遍历。但是,这当然也意味着 ArrayList 不是存储结果的合适数据结构。
-
“逻辑结构是一棵树。最容易用递归函数遍历。但是,这肯定也意味着 ArrayList 不是存储结果的正确数据结构”我也认为,但我不知道怎么做?你知道吗?谢谢:)