对话框伸缩功能(AB伸缩以及ABC伸缩)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhao3132453/article/details/82807494

1、AB伸缩即把一个对话框分为两部分,可以进行伸缩显示

//获得对话框整体范围
	GetWindowRect(&pFull);
	pHalf = pFull;
	//确定小尺寸对话框范围
	CRect rect;
	m_ctlMorebutton.GetWindowRect(&rect);
	pHalf.bottom = rect.bottom + 20;
	pSize = false;//初始设置为小对话框
	//调用改变尺寸函数
	ChangeDlgSize();

void ChangeDlgSize()
{
	CRect rect;
	CString str;
	if(pSize)
	{
		str = "默认<<";
		rect = pFull;
	}
	else
	{
		str = "更多>>";
		rect = pHalf;
	}
	SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE);//显示对话框
	m_ctlMorebutton.SetWindowText(str);//设置按钮文本
	pSize = !pSize;
}

2、ABC伸缩即一个对话框有3个部分,隐藏中间部分B进行伸缩,也就是连接AC

if ((group_expanded && !show) || (!group_expanded && show))
	{
		group_expanded = !group_expanded;

		int i;
		int height = show ? shrinking_height : -shrinking_height;

		// Hide all controls within the group
		for (i=0; i<arAllGroupCtrls.GetSize(); i++){
			if (hCheckBox != arAllGroupCtrls[i]){
				::ShowWindow(arAllGroupCtrls[i], show ? SW_SHOW : SW_HIDE);
			}
		}

		// Move all controls below
		for (i=0; i<arAllCtrlsBelow.GetSize(); i++){
			CRect rcCtrl;
			::GetWindowRect(arAllCtrlsBelow[i], &rcCtrl);
			pDlg->ScreenToClient(rcCtrl);
			rcCtrl.OffsetRect(0, height);
			::MoveWindow(arAllCtrlsBelow[i], rcCtrl.left, rcCtrl.top, rcCtrl.Width(), rcCtrl.Height(), TRUE);
		}

		// Shirnk/Expand dialog
		CRect rcDialog;
		pDlg->GetWindowRect(rcDialog);
		rcDialog.bottom += height;
		pDlg->SetWindowPos(NULL,0,0, rcDialog.Width(), rcDialog.Height(),SWP_NOMOVE | SWP_NOZORDER);
		pDlg->RedrawWindow();
	}

猜你喜欢

转载自blog.csdn.net/zhao3132453/article/details/82807494