一个程序中,创建了一个非模态对话框,为了更加方便,我设置了这个对话框能自由调整窗口大小,控件随之而变大void Cdialogservice::OnSize(UINT nType, int cx, int cy) 
{
CDialog::OnSize(nType, cx, cy); static RECT LastWindowRect = {0, 0, 0, 0};//用来保存窗口上一次的大小
CWnd *hWin;//构造一个句柄
int ux = cx - LastWindowRect.right;

//求出窗口的水平变化量
int uy = cy - LastWindowRect.bottom;

//求出窗口的竖直变化量
if((hWin = GetDlgItem(IDC_LIST1)) != NULL) //IDC_LIST1为控件的ID号
{
RECT rect;
hWin->GetWindowRect(&rect);//获得控件的大小
ScreenToClient(&rect);//设备到客户
rect.right += ux;//
rect.bottom += uy;
hWin->MoveWindow(&rect);//改变控件大小
} if( hWin = m_StatBar)
    {
        RECT rect;
hWin->GetWindowRect(&rect);//获得控件的大小
ScreenToClient(&rect);//设备到客户
rect.right += ux;//
rect.bottom += uy;
hWin->MoveWindow(&rect);//改变控件大小  
    }

LastWindowRect.right = cx;
LastWindowRect.bottom = cy;
}这样设置了之后,一切正常,不过我把窗口最小化,然后还原,这样窗口上的控件都没了,一片空白,我把onsize去掉后,又能正常显示,这种问题是哪里的原因呢,因该怎样解决

解决方案 »

  1.   

    最小化时你调试一下你这个OnSize中的参数值都变成什么了。
      

  2.   

    static RECT LastWindowRect = {0, 0, 0, 0};//
    最小化以后,控件的窗口坐标值都会变成负数,再还原,此时,lastwindowrect为负,
    只需把你的代码进行判断一下
    if( nType != SIZE_MINIMIZED )
    {
     //do your work
    }
      

  3.   

    推荐用我的类http://download.csdn.net/source/1839265
      

  4.   

    static RECT LastWindowRect = {0, 0, 0, 0};//用来保存窗口上一次的大小 
    CWnd *hWin;//构造一个句柄 
    int ux = cx - LastWindowRect.right;这个地方不对,你只对LastWindowRect进行了使用,但是你没有对它正确的初始化。这个初始化不是你用=对它附值为0的过程,而是应该首先记录窗口的大小,然后从第二次开始,你才可以使用该变量。这个修改也非常简单,在
    static RECT LastWindowRect = {0, 0, 0, 0};//用来保存窗口上一次的大小 
    一行后加上对它的初始化:
    if ( LastWindowRect.left == 0 && LastWindowRect.top == 0 && LastWindowRect.right == 0 && LastWindowRect.bottom == 0 )
    {
      LastWindowRect.right = cx;
      LastWindowRect.bottom = cy;
    }