MFC ExpandDlg帮助类

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.csdn.net/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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值