在CView里现实一些图片
可是在刷新的过程中内存越来越大, 不知如何解决.void CZYFloatView::PrintBMP(CDC * pDC,CString bmppath, CRect rect)
{
hDesDC = pDC->m_hDC;
hSrcDC = CreateCompatibleDC(hDesDC);
hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),bmppath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
GetObject(hBitmap, sizeof BITMAP , &bm);
SelectObject(hSrcDC, hBitmap);
::SetStretchBltMode(hDesDC,COLORONCOLOR);  
//::StretchBlt(hDesDC, rect.left, rect.top, 222,222, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,+SRCCOPY);
::StretchBlt(hDesDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,+SRCCOPY);}

解决方案 »

  1.   

    Read a book on Win32 API, carefuly.         hDesDC = pDC->m_hDC;
    hSrcDC = CreateCompatibleDC(hDesDC);
    hBitmap=(HBITMAP)LoadImage(AfxGetInstanceHandle(),bmppath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
    GetObject(hBitmap, sizeof BITMAP , &bm);
    HGDIOBJ hOld = SelectObject(hSrcDC, hBitmap);
    ::SetStretchBltMode(hDesDC,COLORONCOLOR);  
    //::StretchBlt(hDesDC, rect.left, rect.top, 222,222, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,+SRCCOPY);
    ::StretchBlt(hDesDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, hSrcDC, 0, 0, bm.bmWidth, bm.bmHeight,+SRCCOPY);         SelectObject(hSrcDC, hOld);
             DeleteObject(hBitmap);
             DeleteDC(hSrcDC);
      

  2.   

    DeleteObject(hBitmap);
    DeleteDC(hSrcDC);
      

  3.   

    同意袁的,加了现场还原
    申请了资源没释放
    DeleteObject(hBitmap);
    DeleteDC(hSrcDC);
      

  4.   

    袁与虫说的没错.
    申请了的资源一定要释放.
    另外在编写代码的过程中,要养成成对编写的习惯
    当你写了SelectObject后,就要马上写对应的DeleteObject语句;
    用了new后,就要马上编写对应得delete语句
    这样就可以减少很多不必要的资源泄漏