您的位置:首页 > 编程语言 > C语言/C++

孙鑫VC++深入详解:Lesson7 Part3---对话框伸缩功能的实现

2013-07-07 23:24 537 查看
//
// 收缩按钮实现对话框伸缩功能
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(),这按回车键就不会关闭对话框了.
}


//---


//---
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: