/////////////////////////////////////////////////////////////////////////////
// AdoptChildren
//
// Scans all sibling windows and reparent those which are located on top
// of the given window hwndParent.
//
// Usually, hwndParent is either an Elastic or IndexTab control that
// will take charge of resizing its children.
//
// Usually, you will call this routine from the OnInitDialog() event handler.
//
void AdoptChildren(HWND hwndParent)
{
HWND hwndChild, hwndNext;
RECT rcParent, rcChild;
// get parent rect
GetWindowRect(hwndParent, &rcParent);
// scan all controls on the form
hwndChild = GetWindow(hwndParent, GW_HWNDFIRST);
while (hwndChild) {
// save next so we can reparent current child
hwndNext = GetWindow(hwndChild, GW_HWNDNEXT);
// see if this child is contained
GetWindowRect(hwndChild, &rcChild);
if (rcChild.top > rcParent.top && rcChild.left > rcParent.left &&
rcChild.bottom < rcParent.bottom && rcChild.right < rcParent.right) {
// it is, so reparent child
SetParent(hwndChild, hwndParent);
// and move it to the right position
// using SetWindowPos instead of MoveWindow because
// MoveWindow shrinks drop-down panes!!
OffsetRect(&rcChild, -rcParent.left, -rcParent.top);
SetWindowPos(hwndChild, NULL, rcChild.left, rcChild.top, 0, 0,
SWP_NOSIZE | SWP_NOZORDER);
}
// move on
hwndChild = hwndNext;
}
}
|