wince 加载位图资源释放问题
加载位图 、创建各个句柄所增加的内存 最终释放返回成功,但是监视内存实时状态发现增加的内存并没有降下来,这是怎么回事??以下贴出代码
HBitmap m_hBmBkgnd=::LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP10) );
if( m_hBmBkgnd )
{
HBRUSH m_hBrCtl = GetBkBrush(GetSafeHwnd(),IDC_STATIC_JS, m_hBmBkgnd );
}
GetBkBrush( HWND hWnd, UINT nID, HBITMAP hBmBk )
{
#define _X(x) (x.left)
#define _Y(x) (x.top)
#define _W(x) (x.right - x.left)
#define _H(x) (x.bottom - x.top)
HWND hWndCtrl;
hWndCtrl = ::GetDlgItem( hWnd, nID );
HBRUSH hBrushCtrl = NULL;
if( NULL != hWndCtrl )
{
RECT rcCtrl;
::GetWindowRect( hWndCtrl, &rcCtrl );
::ScreenToClient(hWnd, (LPPOINT)&rcCtrl);
::ScreenToClient(hWnd, ((LPPOINT)&rcCtrl)+1);
HDC hDC = ::GetDC(hWnd);
HDC hMemDCBk = CreateCompatibleDC( hDC );
HDC hMemDCCtrl = CreateCompatibleDC( hDC );
HBITMAP hBmCtrl = CreateCompatibleBitmap( hDC, _W(rcCtrl), _H(rcCtrl) );
HBITMAP hBmOldBk;
HBITMAP hBmOldCtrl;
hBmOldBk = (HBITMAP) ::SelectObject( hMemDCBk, hBmBk );
hBmOldCtrl = (HBITMAP) ::SelectObject( hMemDCCtrl, hBmCtrl );
::BitBlt( hMemDCCtrl, 0, 0, _W(rcCtrl), _H(rcCtrl), hMemDCBk, _X(rcCtrl), _Y(rcCtrl), SRCCOPY );
::SelectObject(hMemDCCtrl, hBmOldCtrl );
::SelectObject(hMemDCBk, hBmOldBk );
hBrushCtrl = ::CreatePatternBrush( hBmCtrl );
bool aa;
aa = ::ReleaseDC( hWnd, hDC );//均返回成功实际内存并未真正释放
aa = ::DeleteDC( hMemDCBk );
aa = ::DeleteDC( hMemDCCtrl );
aa =DeleteObject( hBmCtrl );
aa = DeleteObject(hBmOldBk);
aa = DeleteObject(hBmOldCtrl);
}
return hBrushCtrl;
}
[解决办法]
没看代码,请 LZ 确认的是被删除的东东是否有被选入 DC 的,如果有必须先选出,否则无法删除的。