void functon1()
{
CRect rect;
GetClientRect(&rect);tempDrawDC = new CDC;
tempBitmap = new CBitmap;
tempDrawDC->CreateCompatibleDC(NULL);
CBrush tBrush(HS_CROSS, RGB(255,255,255));
tempBitmap->CreateCompatibleBitmap(tempDrawDC,nWidth,nHeight);
tempDrawDC->SelectObject(tempBitmap);
m_Image->Stretch(tempDrawDC->GetSafeHdc(),CRect(-px,-py,nWidth,nHeight));    
}
tempBitmap(Type:CBitmap*),tempDrawDC(Type:CDC*)是类字段;px,py,nWidth,nHeight(Type:long)
为什么在运行一段时间之后会出错误?请大家帮帮忙,在线急等!!!!

解决方案 »

  1.   

    是什么错?你Create出来的东西都不DeleteObject的么?
    Select进DC的东西都不Select出来的么?
      

  2.   

    这可不是个好习惯 NEW完了要删的~
    别忘了
      

  3.   

    刚试了,做了DeleteObject也一样
      

  4.   

    不是啊
    关键是,tempDrawDC是在OnDraw里面也要用
    要不能肯定会在这里删除有没有其它的办法,使得tempDrawDC在OnDraw中使用不会报错
    在线急等
      

  5.   

    代码现在改成这样:
    tempDrawDC = new CDC;
    tempBitmap = new CBitmap; tempDrawDC->CreateCompatibleDC(NULL); tempBitmap->CreateCompatibleBitmap(tempDrawDC,nWidth,nHeight); oldBitmap= tempDrawDC->SelectObject(tempBitmap);
    m_Image->Stretch(tempDrawDC->GetSafeHdc(),CRect(-px,-py,nWidth,nHeight),SRCCOPY);