
MFC 程序,当窗口最小化的时候再点开时,在OnSize()函数中得到的cx,cy怎么是0
voidCAGRIEMDlg::OnSize(UINTnType,intcx,intcy){CDialog::OnSize(nType,cx,cy);m_menu.rcM...
void CAGRIEMDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
m_menu.rcMain.right=cx+3;
CWnd *pWnd=NULL;
pWnd = GetDlgItem(IDC_infotab);
if(pWnd)
{
CRect rect;
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.left=rect.left*cx/rcWindow.Width();
rect.right=rect.right*cx/rcWindow.Width();
rect.top=rect.top*cy/rcWindow.Height();
rect.bottom=rect.bottom*cy/rcWindow.Height();
CString a,b,c,d;
a.Format("%d",rect.right);
b.Format("%d",rect.left);
c.Format("%d",rect.bottom);
d.Format("%d",rect.top);
MessageBox(a+", "+b+" ,"+c+" ,"+d);
pWnd->MoveWindow(rect);
}
GetWindowRect(&rcWindow);
}
最小化到托盘后,再点显示后,会弹出两次我打印的那句话
MessageBox(a+", "+b+" ,"+c+" ,"+d);第一次是窗口的大小,然后是0,0,0,0;把MessageBox弹出的对话框关掉后窗口的控件就没有了、。 展开
{
CDialog::OnSize(nType, cx, cy);
m_menu.rcMain.right=cx+3;
CWnd *pWnd=NULL;
pWnd = GetDlgItem(IDC_infotab);
if(pWnd)
{
CRect rect;
pWnd->GetWindowRect(&rect);
ScreenToClient(&rect);
rect.left=rect.left*cx/rcWindow.Width();
rect.right=rect.right*cx/rcWindow.Width();
rect.top=rect.top*cy/rcWindow.Height();
rect.bottom=rect.bottom*cy/rcWindow.Height();
CString a,b,c,d;
a.Format("%d",rect.right);
b.Format("%d",rect.left);
c.Format("%d",rect.bottom);
d.Format("%d",rect.top);
MessageBox(a+", "+b+" ,"+c+" ,"+d);
pWnd->MoveWindow(rect);
}
GetWindowRect(&rcWindow);
}
最小化到托盘后,再点显示后,会弹出两次我打印的那句话
MessageBox(a+", "+b+" ,"+c+" ,"+d);第一次是窗口的大小,然后是0,0,0,0;把MessageBox弹出的对话框关掉后窗口的控件就没有了、。 展开
2个回答
展开全部
CRect rect;
pWnd->GetWindowRect(&rect);
如ls所述。在窗口还未显示时,GetWindowRect得到的rect的left和top是等于0的。
你可以用GetClientRect得到窗口大小。
pWnd->GetWindowRect(&rect);
如ls所述。在窗口还未显示时,GetWindowRect得到的rect的left和top是等于0的。
你可以用GetClientRect得到窗口大小。
更多追问追答
追问
试了,还是不行。
追答
void CMFCDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
TRACE("%d,%d \r\n",cx,cy);
}
我测试的情况:最小化时,cx = cy = 0。
还原时,cx,cy均ok
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询