Вопрос

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