如果在对话框里添加了CToolBar或者CStatusBar等控件,那么原来的UI会受到影响,可以编写函数重新对窗口布局。如下:
void CMsgManagementDialog::AdjustWindow(CDialog *pParent)
{
ASSERT(pParent != NULL);
ASSERT(pParent->IsKindOf(RUNTIME_CLASS(CDialog)));
CRect rectClientStart;
CRect rectClientNow;
pParent->GetClientRect(rectClientStart);
pParent->RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, rectClientNow);
CPoint ptOffset(rectClientNow.left-rectClientStart.left, rectClientNow.top-rectClientStart.top);
CRect rectChild;
CWnd *pWndChild = pParent->GetWindow(GW_CHILD);
while(pWndChild)
{
pWndChild->GetWindowRect(rectChild);
pParent->ScreenToClient(rectChild);
rectChild.OffsetRect(ptOffset);
pWndChild->MoveWindow(rectChild, FALSE);
pWndChild = pWndChild->GetNextWindow();
}
CRect rectWindow;
pParent->GetWindowRect(rectWindow);
rectWindow.right += rectClientStart.Width()-rectClientNow.Width();
rectWindow.bottom += rectClientStart.Height()-rectClientStart.Height();
pParent->MoveWindow(rectWindow, FALSE);
pParent->RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
pParent->CenterWindow();
}