Question

I am currently trying to get the text of a control and while going down from the top window to the control I needed I got stuck in this control which has multiple chield with 2 controls having the same class name.

Debug sample code as illustration:

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... :/

Here is an image of the child control I am at right now: child control with multiple controls

I need from ATL:00622208 exactly the 2nd control #32770 (Dialog) but how do I read only the second one using FindWindowEx to move to the next control ?

Was it helpful?

Solution

Once you have the window handle 'IntPtr' you can get the list of child windows like this...

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

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

You can find the pinvoke needed for the Win32 GetWindow from here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top