在对话框初始化时 GetClientRect(&m_OldRect);         ShowWindow(SW_MAXIMIZE);//使程序进来时对话框最大话
写了个方法:用于调整控件变化
void CEmpDataMa::updateIDRect(CRect m_oldrect,int cx,int cy)
{
CWnd *pWnd; 
int idc[10]={IDC_BTN_EmpBack,IDC_CHECK_ChangePassword,IDC_CHECK_EmpInfos,IDC_CHECK_EmpOut,IDC_CHECK_SetBumen,IDC_CHECK_SetSysD,
IDC_CHECK_ShuokaDa,IDC_CHECK_Time_shuoka,IDC_STATIC_EmpMFunc,IDC_STATIC_ChildDlgPic};
int i,num =10 ; for(i=0;i<=num;i++)
{
pWnd = GetDlgItem(idc[i]); 
if(pWnd)
{
CRect rect;   //获取控件变化前的大小
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);//将控件大小转换为在对话框中的区域坐标
rect.left=rect.left*cx/m_oldrect.Width();/////调整控件大小
rect.right=rect.right*cx/m_oldrect.Width();
rect.top=rect.top*cy/m_oldrect.Height();
rect.bottom=rect.bottom*cy/m_oldrect.Height();
pWnd->MoveWindow(rect);//设置控件大小
}
}}void CEmpDataMa::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
/*if (cx==0||cy==0)
{
cx = 800;
cy = 600;
}*/
updateIDRect(m_OldRect,cx,cy);
GetClientRect(&m_OldRect);
}
现在的问题是:最大化可以,我点击最小化时,会停在屏幕的左下方,当我在点击还原原来大小时会出错。有哪位高手可以纠正一下????

解决方案 »

  1.   

    补充下:问题出在当最小化时cx,cy,m_oldrect这些值为0,请问,如何能得到最小化之前的那个m_oldrect???关键所在谁能解答,给分!!!
      

  2.   

    重新编写下“还原”的代码:发送一个RESTORE的消息
      

  3.   

    http://www.codeproject.com/KB/dialog/RPResizeDlg.aspx
      

  4.   

    CWnd::OnSize  
    afx_msg void OnSize( UINT nType, int cx, int cy );ParametersnTypeSpecifies the type of resizing requested. This parameter can be one of the following values: SIZE_MAXIMIZED   Window has been maximized.
    SIZE_MINIMIZED   Window has been minimized.
    SIZE_RESTORED   Window has been resized, but neither SIZE_MINIMIZED nor SIZE_MAXIMIZED applies.
    SIZE_MAXHIDE   Message is sent to all pop-up windows when some other window is maximized.
    SIZE_MAXSHOW   Message is sent to all pop-up windows when some other 
      

  5.   

    你在WM_SYSCOMMAND消息你处理最小化不行吗?
      

  6.   

    问题解决用下列方法解决的:有需要的朋友可以参考
    对话框中有个属性-Application Window设为true 最小话时显示在任务栏用一个BOOL型变量,初始为false
    OnSysCommand里拦截最小话消息设为true
    onsize里若为false在执行、、、、、、