//
// 收缩按钮实现对话框伸缩功能
void CTestDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CString str;
if(GetDlgItemText(IDC_BUTTON2,str),str=="收缩<<")
{
SetDlgItemText(IDC_BUTTON2,"伸展>>");
}
else if(str=="伸展>>")
{
SetDlgItemText(IDC_BUTTON2,"收缩<<");
}
static CRect rectLarge,rectSmall;
CRect rectSeparator;
if(rectLarge.IsRectEmpty())
{
GetWindowRect(&rectLarge);
GetWindowRect(&rectSmall);
GetDlgItem(IDC_SEPERATOR)->GetWindowRect(&rectSeparator);
rectSmall.bottom = rectSeparator.bottom;
}
if(str=="收缩<<")
{
// 用了SWP_NOZORDER,就忽略第一个参数,故用NULL
// 用SWP_NOMOVE,就忽略了x和y,故用0,0
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);
}
}
//CTestDlg::OnOK() 覆盖基类的OnOk(),但是它末尾还是调用了基类的CDialog::OnOK(),因为要注释掉它
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK(); //注释掉基类的OnOk(),这按回车键就不会关闭对话框了.
}
//---
//---
本文介绍了一种在对话框中实现伸缩效果的方法。通过修改按钮文本与窗口位置大小来达到视觉上的伸展与收缩效果。具体实现包括记录对话框的原始尺寸与收缩尺寸,并在点击按钮时切换这两种状态。
2397

被折叠的 条评论
为什么被折叠?



