1. 當點擊Unexpand的時候 圖像控件 以下部分展開,再次點擊 圖像控件以下部分收縮;Dialog圖:
2.實現功能的代碼 ,請參看註釋:
void CtestDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知處理程序代碼
CString str;
if(GetDlgItemText(IDC_BUTTON2,str),str == L"Unexpand<<")//點擊Unexpand 呈展開顯示文字
{
SetDlgItemText(IDC_BUTTON2,L"expand>>");
}
else
{
SetDlgItemText(IDC_BUTTON2,L"Unexpand<<");//點擊expand 呈收縮顯示文字
}
static CRect rectLarge;//保留還原後的Dialog窗口大小,靜態 保留原始尺寸不變。
static CRect rectSmall;//保留收縮後的Dialog窗口大小;收縮後尺寸也不變
if(rectLarge.IsRectNull())//獲取原Dialog大小
{
CRect rectSeparator;
GetWindowRect(&rectLarge);
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator);//獲取圖像分隔符的矩形座標
rectSmall.left = rectLarge.left;
rectSmall.top = rectLarge.top;
rectSmall.right= rectLarge.right;
rectSmall.bottom= rectSeparator.bottom;//根據展開和收縮方式,唯獨有底部收縮。底部座標改變
}
if("Unexpand<<"==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);//設施展開窗口位置
}
}