문제

I am wondering when working with HDCs, when I select back the original bitmap, can I use it again? Like...

HBITMAP hbmOld;

// FIRST
hbmOld = (HBITMAP)SelectObject(hdcMem, bitmap.hbmItemOverlay);    
Rectangle(hdcMem, 0, 0, MAP_WIDTH*BLOCK_SIZE, MAP_HEIGHT*BLOCK_SIZE); 
SelectObject(hdcMem, hbmOld);

// SECOND
stockBrush = GetStockBrush(BLACK_BRUSH);
hbmOld = (HBITMAP)SelectObject(hdcMem2, bitmap.hbmMap);
Rectangle(hdcMem2, 0, 0, bitmap.bmMap.bmWidth, bitmap.bmMap.bmHeight);
SelectObject(hdcMem2, hbmOld);

I am wondering if that is valid. It compiles fine and works, but I was wondering if it's bad programming practice to do that?

도움이 되었습니까?

해결책

This seems perfectly fine in my opinion.

You could also test for memory leaks just to be 100% sure.

I personally use GDIView to do this. The key is for number of handles to be constant in the last column. If you need help with using it leave a comment. I would welcome if others can suggest better or easier to use alternative.

Best regards.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top