对话框的收缩与拓展

  有时候,我们点击按钮,对话框就会扩大或则缩小!这是怎么做到的呢?

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);
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值