注册 登录
编程论坛 VC++/MFC

MFC中关于对话框扩展的问题,求助~

徐士昊 发布于 2013-10-29 12:26, 405 次点击
对话框出现时开始是小的
对话框的OnInitDialog()函数中添加如下代码
                    SetDlgItemText(IDC_BUTTON2,"扩展>>");
            CRect SmallRect;
            CRect  LargeRect;
            CRect Separetor;
            GetWindowRect(&LargeRect);//获得对话框原始位置
            GetDlgItem(IDC_SEPARATOR)->    GetWindowRect(&Separetor);//获取图像控件的原始位置
            SmallRect.left=LargeRect.left;
            SmallRect.top=LargeRect.top;
            SmallRect.bottom=Separetor.bottom;
            SmallRect.right=LargeRect.right;
            SetWindowPos(NULL,0,0,SmallRect.Width(),SmallRect.Height(),SWP_NOMOVE|SWP_NOZORDER);
按钮响应函数为
void CExDialogDlg::OnButton2()
{
    // TODO: Add your control notification handler code here
    CString str;
    if(GetDlgItemText(IDC_BUTTON2,str),str=="收缩<<")
    {
        SetDlgItemText(IDC_BUTTON2,"扩展>>");
    }
    else
    {
        SetDlgItemText(IDC_BUTTON2,"收缩<<");
    }
            
    static CRect LargeRect;
    static CRect SmallRect;
        
        if(LargeRect.IsRectNull())
        {
            CRect Separetor;
            GetWindowRect(&LargeRect);//获得对话框原始位置
            GetDlgItem(IDC_SEPARATOR)->    GetWindowRect(&Separetor);//获取图像控件的原始位置
            SmallRect.left=LargeRect.left;
            SmallRect.top=LargeRect.top;
            SmallRect.bottom=Separetor.bottom;
            SmallRect.right=LargeRect.right;
        }
   
    if(GetDlgItemText(IDC_BUTTON2,str),str=="收缩<<")
    {
        SetWindowPos(NULL,0,0,LargeRect.Width(),LargeRect.Height(),SWP_NOMOVE|SWP_NOZORDER);
   
    }
    else
    {
        SetWindowPos(NULL,0,0,SmallRect.Width(),SmallRect.Height(),SWP_NOMOVE|SWP_NOZORDER);
    }

   
}

运行没错误,在点击按钮的时候无法实现功能。
当注释掉OnInitDialog()中的 SetWindowPos(NULL,0,0,SmallRect.Width(),SmallRect.Height(),SWP_NOMOVE|SWP_NOZORDER);时又可以正常使用。
求大神指导
1 回复
#2
yuccn2013-10-29 13:33
不知道你说什么,

你想干什么?
你的问题是什么?
无法实现什么?
1