读书人

一个除以0的错误怎样解决?函数定义

发布时间: 2012-09-01 09:33:02 作者: rapoo

一个除以0的异常,怎样解决?函数定义也有,求正解
RT,

调试的时候会出现这个“ 0x00d9f416 处有未经处理的异常: 0xC0000094: Integer division by zero”
怎么解决?



以下是函数定义:


C/C++ code
void CELDlg::autosize(UINT nID,LPRECT lpRect)  {      CWnd *pWnd;      pWnd = GetDlgItem(nID);   //获取控件句柄      if(!pWnd) return;         //判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建        CRect rect,recttemp;       //定义rect为控件变化后的参数          GetClientRect(&recttemp);  //recttemp获取变化后对话框客户区大小        //计算各个参数值,利用每个值主窗口的相对值计算      rect.left = recttemp.Width() * lpRect->left/m_rectmin.Width();      rect.right = recttemp.Width() * lpRect->right/m_rectmin.Width();      rect.top = recttemp.Height() * lpRect->top/m_rectmin.Height();      rect.bottom = recttemp.Height() * lpRect->bottom/m_rectmin.Height();        pWnd->MoveWindow(rect);//调整控件位置  } 


[解决办法]
void CEBankDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);

CRect rc;

CWnd *pWnd = GetDlgItem(IDC_STA);
if(pWnd && nType != 1)
{
for(int i=0; i < 5; ++i)
{
pWnd->GetWindowRect(&rc);
ScreenToClient(&rc);

if(m_ClienRc.Width() <= 0 || m_ClienRc.Height() <= 0)
{
pWnd->MoveWindow(rc);
pWnd = GetNextDlgGroupItem(pWnd);
}
else
{
rc.left = rc.left * cx / m_ClienRc.Width();
rc.right= rc.right* cx / m_ClienRc.Width();
rc.top = rc.top * cy / m_ClienRc.Height();
rc.bottom=rc.bottom*cy / m_ClienRc.Height();

pWnd->MoveWindow(rc);
pWnd = GetNextDlgGroupItem(pWnd);
}
}
}
GetClientRect(&m_ClienRc);
Invalidate(TRUE);
}

读书人网 >VC/MFC

热点推荐