Hi,
what is the standard way to enumerate all windows within a groupbox?
I wonder since I have a groupbox in which I have placed several controls
such as editbox, textfield, button etc. Now, under certain circumstances I'd
like to process all of those "contained" controls.
First I thought that I'd loop them by first setting up a tab order in such
way that the groupbox is first and then just do:
CWnd* pWnd = this;
while (pWnd && !Finished)
{
DoStuff(pWnd);
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
But I do not know how to set Finished...
The other approach was to do an IntersectRect to see which controls lies
within the gropbox:
CWnd* pWnd = GetParent()->GetWindow(GW_CHILD);
while (pWnd)
{
pWnd->GetWindowRect(rectWnd);
if (pWnd != this && rectTmp.IntersectRect(rectGroupbox, rectWnd))
{
DoStuff(pWnd);
}
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
However, this fails due to controls such as other groupboxes may contain the
current groupbox which results in that the other control gets processed as
well by our DoStuff method.
This can of course be worked around by calculating x and y positions and add
the following to the if-statement above:
rectGroupbox.TopLeft().x > rectWnd.TopLeft().x &&
rectGroupbox.TopLeft().y < rectWnd.TopLeft().y
But this feels like a hack :-(
So I wonder which is the standard way to do this kind of loop?
Thanks in advance,
/Tom