void CTestDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
CString str;
if (GetDlgItemText(IDC_BUTTON2, str), str == "收缩")
{
SetDlgItemText(IDC_BUTTON2, "扩展");
}
else
{
SetDlgItemText(IDC_BUTTON2, "收缩");
}
CRect rectLarge;
CRect rectSmall;
if (rectLarge.IsRectNull())
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(ID_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.left = rectLarge.left;
rectSmall.top= rectLarge.top;
rectSmall.right = rectLarge.right;
rectSmall.bottom = rectSeparator.bottom;
}
if (str == "收缩")
{
SetWindowPos(NULL, 0, 0, rectSmall.Width(), rectSmall.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
else
{
SetWindowPos(NULL, 0, 0, rectLarge.Width(), rectLarge.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
{
// TODO: 在此添加控件通知处理程序代码
CString str;
if (GetDlgItemText(IDC_BUTTON2, str), str == "收缩")
{
SetDlgItemText(IDC_BUTTON2, "扩展");
}
else
{
SetDlgItemText(IDC_BUTTON2, "收缩");
}
CRect rectLarge;
CRect rectSmall;
if (rectLarge.IsRectNull())
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(ID_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.left = rectLarge.left;
rectSmall.top= rectLarge.top;
rectSmall.right = rectLarge.right;
rectSmall.bottom = rectSeparator.bottom;
}
if (str == "收缩")
{
SetWindowPos(NULL, 0, 0, rectSmall.Width(), rectSmall.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
else
{
SetWindowPos(NULL, 0, 0, rectLarge.Width(), rectLarge.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
}
---------------------------------------------------------------------------------------------------------------------
在按钮的方法下,定义变量CString str;
使用GetDLgItemText()进行判断
使用SteDlgItemText()设置
在对话框上增加分隔符,用以表示切割部分,分隔符可用图像控件来表示
定义CRect变量,判断是否为空IsRectEmpty/IsRectNull,定义分隔符变量获取分隔符信息尺寸,将对话框右下角信息即底部的高,再判断是否为对应按钮字符str
来使用SetWindowPos进行判断设置