Knowledge Base Nr: 00311 expanddlg.cpp - http://www.swe-kaiser.de

Downloads:

MFC: Expandable Dialog (dialog dynamisch in größe und verhalten ändern)

  
- in dialog 2 controls einfügen (invisible setzen) - position bestimmt später dialoggröße

- messagehandler einfügen z.b. button

void CUserDlg::OnExpand()
{
CRect rect;
GetWindowRect(&rect);
int nNewHeight = -1;

if (m_bExpanded)
{
m_bExpanded = false;

GetDlgItem(IDC_EXPAND)->SetWindowText(theApp.Translate(L"Erweitert >>"));

CRect rectSmall;
GetDlgItem(IDC_SMALL)->GetWindowRect(&rectSmall);
nNewHeight = rectSmall.top - rect.top;
}
else
{
m_bExpanded = true;

GetDlgItem(IDC_EXPAND)->SetWindowText(theApp.Translate(L"Erweitert <<"));

CRect rectBig;
GetDlgItem(IDC_BIG)->GetWindowRect(&rectBig);
nNewHeight = rectBig.top- rect.top;
}

SetWindowPos(NULL, 0, 0, rect.Width(), nNewHeight, SWP_NOMOVE|SWP_NOZORDER);

//enable controls if visible
CWnd* pWnd = GetWindow(GW_CHILD);
while (pWnd != NULL)
{
CRect rectCtrl;
pWnd->GetWindowRect(&rectCtrl);
pWnd->EnableWindow(rectCtrl.top <= rect.top + nNewHeight);

pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}

//set focus to first control
GetDlgItem(IDC_USER)->EnableWindow(m_bUserChangeable);
GetDlgItem(IDC_USER)->SetFocus();
}