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

C# 读取具有多个子控件且类具有相同名称的子控件?,c#,gettext,spy++,C#,Gettext,Spy++,我目前正在尝试获取一个控件的文本,当我从顶部窗口转到所需的控件时,我被困在这个控件中,该控件有多个chield,其中两个控件具有相同的类名 调试示例代码,如图所示: IntPtr window = FindWindow("MainControl", "WindowTitle"); iData.Text += window.ToString("X") + Environment.NewLine; IntPtr control = FindWindowEx(window, IntPtr.Zero,

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

调试示例代码,如图所示:

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... :/
下面是我现在所在的子控件的图像:


我需要从
ATL:00622208
中找到第二个控件
#32770(对话框)
,但如何使用FindWindowEx只读取第二个控件以移动到下一个控件?

一旦有了窗口句柄“IntPtr”,您就可以得到如下子窗口列表

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

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

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

谢谢您的回答,但正如您所看到的,我正在获取子对象的子对象,在您所说的上下文中情况如何?我尝试使用Control.FromHandle和FromChildHandle,但两者都失败,窗口确实有窗口句柄,但c总是空的。看来我错了。FromHandle仅在.NET已经有一个与该句柄关联的控件时才起作用,而您的情况并非如此。我已经更新了回复,以使用不同的方法。