有时候,我们点击按钮,对话框就会扩大或则缩小!这是怎么做到的呢?
void CControlDlg::OnButton2() //控件处理函数,caption设置为small
{
// TODO: Add your control notification handler code here
CString str;
if(GetDlgItemText(IDC_BUTTON2,str),str=="small")
{
SetDlgItemText(IDC_BUTTON2,"large");
}
else
{
SetDlgItemText(IDC_BUTTON2,"small");
}
static CRect rectSmall;//这里定义为静态的成员变量!因为每一次的增大和缩小,并不需要创建新的对话框!而且初始的时候为0
static CRect rectLarge;
if(rectLarge.IsRectNull())//这里注意和rectLarge.IsRectEmpty()的区别,前者为0,0,0,0时候,返回为0.后者则不能构成矩形时候返回0
{
CRect rectSeparator;
GetWindowRect(&rectLarge);//获取当前函数的窗口大小
GetDlgItem(IDC_Separator)->GetWindowRect(&rectSeparator);//获取分隔条窗口的大小
rectSmall.top=rectLarge.top;
rectSmall.left=rectLarge.left;
rectSmall.right=rectLarge.right;
rectSmall.bottom=rectSeparator.bottom;
}
if(str=="small")
{
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);
}
}