class CDlgExpander
{
BOOL m_bIsInitialized;
BOOL m_bIsExpanded;
int m_IdExpandButton;
int m_IdCollapsedMark;
CWnd *m_pDialog;
CRect m_dialogrect;
public:
CDlgExpander()
{
m_bIsInitialized = FALSE;
};
// call this function from the OnInitDialog() function
void Initialize(CWnd *pDialog, // pointer to dialog
BOOL bInitiallyExpanded, // TRUE => dialog is initially expanded
int IdExpandButton, // id of " More " / " Less " button
int IdCollapsedMark) // id of static that indicates position of
// the bottom of the collapsed dialog
{
m_IdExpandButton = IdExpandButton;
m_IdCollapsedMark = IdCollapsedMark;
m_bIsInitialized = TRUE;
m_pDialog = pDialog;
m_bIsExpanded = FALSE;
m_pDialog->GetWindowRect(&m_dialogrect); // rectangle of the dialog window
//m_pDialog->GetDlgItemText(IdExpandButton, m_sTextMore);
//m_pDialog->GetDlgItemText(IdCollapsedText, m_sTextLess);
//CWnd *pWndMark = m_pDialog->GetDlgItem(m_IdCollapsedText);
//pWndMark->ShowWindow(SW_HIDE); // hide the "delimiting" control
//pWndMark = m_pDialog->GetDlgItem(m_IdCollapsedMark);
//pWndMark->ShowWindow(SW_HIDE); // hide the "delimiting" control
if (bInitiallyExpanded)
{
CWnd *pButton = m_pDialog->GetDlgItem(m_IdExpandButton);
//pButton->SetWindowText(m_sTextLess);
}
else
OnExpandButton();
}
void ShrinkDialog(CWnd *pDlg, int idmark)
{
ASSERT(pDlg != NULL);
CWnd *pWndMark = pDlg->GetDlgItem(idmark);
ASSERT(pWndMark != NULL);
CRect markrect;
CRect dlgrect;
CRect clientrect;
CWnd *pParentWnd = pDlg->GetParent();
pDlg->GetClientRect(&clientrect); // clientrect of the dialog
pDlg->GetWindowRect(&dlgrect); // rectangle of the dialog window
// get height of the title bar
//
int offset = dlgrect.Height() - clientrect.bottom + 5;
pWndMark->GetWindowRect(&markrect);
pDlg->ScreenToClient(&markrect);
// calculate the new rectangle of the dialog window
dlgrect.bottom = dlgrect.top + markrect.bottom + offset;
pDlg->MoveWindow(dlgrect.left, dlgrect.top, dlgrect.Width(), dlgrect.Height());
}
void OnExpandButton()// call this in the handler of the "More"/"Less" button
{
ASSERT(m_bIsInitialized);
m_bIsExpanded = !m_bIsExpanded;
if (m_bIsExpanded)
{
// ShrinkDialog(m_pDialog, m_IdExpandedMark) ;
CRect rect;
m_pDialog->GetWindowRect(&rect);
rect.bottom = rect.top + m_dialogrect.Height();
rect.right = rect.left + m_dialogrect.Width();
m_pDialog->MoveWindow(&rect);
}
else
ShrinkDialog(m_pDialog, m_IdExpandButton);
//ShrinkDialog(m_pDialog, m_IdCollapsedMark);//shrink by static text(flag mark)
CWnd* pButton = m_pDialog->GetDlgItem(m_IdExpandButton);
//pButton->SetWindowText(!m_bIsExpanded ? m_sTextMore : m_sTextLess);
}
};
https://blog.youkuaiyun.com/chenlu5201314/article/details/47151675?spm=1035.2023.3001.6557&utm_medium=distribute.pc_relevant_bbs_down_v2.none-task-blog-2defaultOPENSEARCHRate-3-47151675-bbs-300172451.pc_relevant_bbs_down_v2_default&depth_1-utm_source=distribute.pc_relevant_bbs_down_v2.none-task-blog-2defaultOPENSEARCHRate-3-47151675-bbs-300172451.pc_relevant_bbs_down_v2_default