在Dialog中放置一个按钮和一个图像控件
按钮ID:IDC_BUTTON1
图像控件ID:IDC_SEPARATOR
//作为分隔条
并设置图像控件visble不可见,勾选sunken(凹陷)
窗体如图:

代码:
void CTest0610Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString str;
if(GetDlgItemText(IDC_BUTTON1,str),str=="收缩<<")
{
SetDlgItemText(IDC_BUTTON1,"扩展>>");
}
else
{
SetDlgItemText(IDC_BUTTON1,"收缩<<");
}
static CRect rectLarge;
//完整窗体矩形
static CRect rectSmall;
//缩小窗体矩形
if(rectLarge.IsRectNull())
//如果窗体矩形为空
{
GetWindowRect(&rectLarge);
CRect rectSeparator;
//分隔条矩形
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);
rectSmall.left=rectLarge.left;
rectSmall.top=rectLarge.top;
rectSmall.right=rectSeparator.right;
rectSmall.bottom=rectLarge.bottom;
}
if(str=="收缩<<")
{
//设置窗体
//参数1:z次序,设置样式SWP_NOZORDER(无Z次序)时忽略此参数
//参数2、3:窗体矩形左上角坐标,
设置样式
SWP_NOMOVE (不移动)
时忽略此参数
//参数4、5:窗体矩形宽和高
//参数6:样式
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);
}
}
运行效果:

