2

我目前正在尝试获取控件的文本,并且在从顶部窗口向下移动到我需要的控件时,我陷入了该控件中,该控件具有多个子项,其中 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... :/

这是我现在所在的子控件的图像: 具有多个控件的子控件

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

4

1 回答 1

2

一旦你有了窗口句柄'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 。

于 2011-05-24T23:59:38.773 回答