首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

上面这段代码哪有有关问题?各位帮忙看上

2012-07-25 
下面这段代码哪有问题?各位帮忙看下C/C++ codevoid CMFCDlg::OnSize(UINT nType, int cx, int cy) {CDialo

下面这段代码哪有问题?各位帮忙看下

C/C++ code
void CMFCDlg::OnSize(UINT nType, int cx, int cy) {    CDialog::OnSize(nType, cx, cy);    int dX = cx - pointOld.x;    int dY = cy - pointOld.y;    if (nType = SIZE_MINIMIZED)        dX = dY = 0;    CWnd *pWndOK =GetDlgItem(IDOK);    CRect rectOk;    pWndOK->GetWindowRect(&rectOk);//有问题的一行    rectOk.left *= dX;    rectOk.top *= dY;    int newWidth = rectOk.Width()*dX;    int newHeight =rectOk.Height()*dY;    pWndOK->MoveWindow(rectOk.left,rectOk.top,newWidth,newHeight);    pointOld.x = cx;    pointOld.y = cy;    }

程序执行到pWndOK->GetWindowRect(&rectOk);就出现内存错误

[解决办法]
pWndOK 看看是有效的吗
[解决办法]
CWnd *pWndOK =GetDlgItem(IDOK);
if(pWndOK && pWndOK ->GetSafeHandle() )
{
 pWndOK->GetWindowRect(&rectOk);
}

热点排行