c# - 读取具有多个具有相同名称的类的子控件的子控件?

标签 c# gettext spy++

我目前正在尝试获取一个控件的文本,当我从顶部窗口向下转到我需要的控件时,我被困在这个控件中,它有多个 chield,其中 2 个控件具有相同的类名。

如图所示调试示例代码:

IntPtr window = FindWindow("MainControl", "WindowTitle");
iData.Text += window.ToString("X") + Environment.NewLine;

IntPtr control = FindWindowEx(window, IntPtr.Zero, "CMainWindow", null);
iData.Text += control.ToString("X") + Environment.NewLine;

IntPtr control2 = FindWindowEx(control, IntPtr.Zero, "My_SplitterWindow", null);
iData.Text += control2.ToString("X") + Environment.NewLine;

IntPtr control3 = FindWindowEx(control2, IntPtr.Zero, "ATL:0061FA08", null);
iData.Text += control3.ToString("X") + Environment.NewLine;

IntPtr control4 = FindWindowEx(control3, IntPtr.Zero, "ATL:0061E168", null);
iData.Text += control4.ToString("X") + Environment.NewLine;

IntPtr control5 = FindWindowEx(control4, IntPtr.Zero, "ATL:00620118", null);
iData.Text += control5.ToString("X") + Environment.NewLine;

IntPtr control6 = FindWindowEx(control5, IntPtr.Zero, "ATL:00622208", null);
iData.Text += control6.ToString("X") + Environment.NewLine;

// stucked here... :/

这是我现在所在的子控件的图像: child control with multiple controls

我需要来自 ATL:00622208 的第二个控件 #32770 (Dialog) 但是如何使用 FindWindowEx 只读取第二个控件以移动到下一个控件?

最佳答案

一旦有了窗口句柄“IntPtr”,您就可以像这样获取子窗口列表...

IntPtr window = FindWindowEx("MainControl", "WindowTitle");

IntrPtr child = GetWindow(window, GW_CHILD | GW_HWNDFIRST);
while(child != IntPtr.Zero)
{
     child = GetWindow(child, GW_HWNDNEXT);
}

您可以从here 找到Win32 GetWindow 所需的pinvoke。 .

关于c# - 读取具有多个具有相同名称的类的子控件的子控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6118116/

相关文章:

c# - 在 File.Exists 上找不到文件,路径中有空格

c# - 多个 POST 参数,一些包含 XML

PHP 本地化最佳实践?获取文本?

variables - 我可以在 .po 文件中包含变量吗?

c# - 如何从另一个应用程序读取 QTextEdit 内容?

c# - 如何在我的 C# 应用程序中获得类似于 Spy++ 的功能?

c# - 如何检测功能区上切换按钮的状态?

python - 我可以同时调用和设置库中的 Python gettext 模块和使用它的模块吗?

c# - 如何从 Windows 中打开的应用程序中读取值?

c# - 如何在 SoapHttpClientProtocol 中设置 User-Agent header ?