点击一个控件,使对话框收缩或者扩展
//整体思路:
/*
1,产生一个控件,点击一下改变对话框中的文字,使用GetDlgItemText(..),SetDlgItemText(..)
2, 使用一个CRect储存原有位置,用GetWindowRect()来获得一个对话框的位置信息
3, 判断文字,如果是“收缩<<”,就改小对话框的尺寸大小,如果是“扩展>>”,就改大对话框尺寸大小
*/
CString str;
if(GetDlgItemText(IDC_BUTTON1,str),str=="收缩<<")
{
SetDlgItemText(IDC_BUTTON1,"扩展>>");
}
else
{
SetDlgItemText(IDC_BUTTON1,"收缩<<");
}
static CRect rectLarge; //储存当前的控件的坐标
static CRect rectSmall; //储存分割后控件的坐标
if(rectLarge.IsRectEmpty())
{
CRect rectSeparator; //储存分割线的坐标值
GetWindowRect(&rectLarge); //获取当前对话框的位置坐标
GetDlgItem(IDC_SEPARATOR)->GetWindowRect(&rectSeparator); //获取分割线对话框的坐标位置
//分割后的值
rectSmall.left=rectLarge.left;
rectSmall.right=rectLarge.right;
rectSmall.top=rectLarge.top;
rectSmall.bottom=rectSeparator.bottom; //注意*
}
if(str=="收缩<<")
{
//This method changes the size, position, and z-order of child, pop-up, and top-level windows
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); //重新设置对话框的长度
}