alsmorris
asked on
The correct way to DeletObject
Hi,
I've read a ton of different info. on how to clean up bitmap objects but alot of the information is different. Can someone explain what the correct method is for cleaning up a GDI object such as a bitmap. I.E.
HDC pDC = ::GetWindowDC(hWnd);
hBitmapDC = ::CreateCompatibleDC(pDC);
HBITMAP hBitmap = ::LoadBitmap(hInst,(LPCTST R)nResID);
::SelectObject(hBitmapDC,h Bitmap );
::BitBlt(pDC,0,0,10,10,hBi tmapDC,0,0 ,SRCCOPY);
...How do I clean up properly?
I've read a ton of different info. on how to clean up bitmap objects but alot of the information is different. Can someone explain what the correct method is for cleaning up a GDI object such as a bitmap. I.E.
HDC pDC = ::GetWindowDC(hWnd);
hBitmapDC = ::CreateCompatibleDC(pDC);
HBITMAP hBitmap = ::LoadBitmap(hInst,(LPCTST
::SelectObject(hBitmapDC,h
::BitBlt(pDC,0,0,10,10,hBi
...How do I clean up properly?
ASKER
MattAA,
I have tried this but I get resource errors... and finally the window goes black. I am finding out that what works on 2000/XP does not work on 98. For example what you said ::DeleteObject(hBitmap); will not give me a problem on 2000/xp but on 98 I get a black window and boundchecker tells me that the object is still selected in the DC.
Thanks :)
I have tried this but I get resource errors... and finally the window goes black. I am finding out that what works on 2000/XP does not work on 98. For example what you said ::DeleteObject(hBitmap); will not give me a problem on 2000/xp but on 98 I get a black window and boundchecker tells me that the object is still selected in the DC.
Thanks :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok ... I think I figured it out...But I'm not sure this is the best way to do it...
HDC pDC = ::GetWindowDC(hWnd);
hBitmapDC = ::CreateCompatibleDC(pDC);
HBITMAP hBitmap = ::LoadBitmap(hInst,(LPCTST R)nResID);
HBITMAP hOld = ::SelectObject(hBitmapDC,h Bitmap );
::BitBlt(pDC,0,0,10,10,hBi tmapDC,0,0 ,SRCCOPY);
::SelectObject(hBitmapDC,h Old);
::DeleteObject(hBitmap);
::DeleteDC(hBitmapDC);
HDC pDC = ::GetWindowDC(hWnd);
hBitmapDC = ::CreateCompatibleDC(pDC);
HBITMAP hBitmap = ::LoadBitmap(hInst,(LPCTST
HBITMAP hOld = ::SelectObject(hBitmapDC,h
::BitBlt(pDC,0,0,10,10,hBi
::SelectObject(hBitmapDC,h
::DeleteObject(hBitmap);
::DeleteDC(hBitmapDC);
That's about how DC/Object stuff goes. You really need to keep it nicely cleared up for 98/etc because, if I'm not mistaken after this long, there are limited DC and GDI handles.
Actually, just repeating the SelectObject(hBitmapDC, hBitmap) call should restore by itself.
::DeleteObject(hBitmap);
You should also delete your memory device context (hBitmapDC) with ::DeleteDC when you are done with it.