I have the following code in the WM_PAINT message handler of the main window :
void BossController::paint ( HWND hwnd, HBITMAP skin )
{
PAINTSTRUCT ps;
HDC hdc;
hdc = BeginPaint ( hwnd, &ps );
HDC dcSkin = CreateCompatibleDC ( hdc ); // memory dc for skin
HDC hMemDc = CreateCompatibleDC ( hdc ); // memory dc for painting
HBITMAP hmemBmp = CreateCompatibleBitmap ( hdc, width, height ); // Create bitmap to draw on
HBITMAP hOldMemBmp = (HBITMAP)SelectObject ( hMemDc, hmemBmp ); // select memory bitmap in memory dc
HBITMAP hOldSkinBmp = (HBITMAP)SelectObject ( dcSkin, skin ); //select skin bitmap in skin memory dc
BitBlt ( hMemDc, 0, 0, width, height, dcSkin, 0, 0, SRCCOPY ); // Paint Skin on Memory DC
BitBlt ( hdc, 0, 0, width, height, hMemDc, 0, 0, SRCCOPY ); // Paint Skin on Window DC
DeleteObject ( hOldSkinBmp );
DeleteObject ( hOldMemBmp );
DeleteObject( hmemBmp );
DeleteDC ( hMemDc );
DeleteDC ( dcSkin );
EndPaint ( hwnd, &ps );
};
I will be painting text on the skin aswell, that's why I am BitBlt ing on memory DC with a memory bitmap, I have tried with straight painting(directly to hdc) as well, but none worked, and I am not sure how to debug it. The only thing I could check was to check the skin against NULL in LoadBitmap function's return value and also in the void BossController::paint ( HWND hwnd, HBITMAP skin ). And BitBlt's return value.
It always shows a rectangle with the background color I chose while creating the window. (window is a custom skinned one so, no title bar etc is there.
Can someone point out the errors if any or the potential pitfalls or maybe how to debug it ?
hOld*
bitmaps. Instead, select them back into their DCs before deleting anything. I don't think that's your problem, though. – rodrigoskin
- I guessHBITMAP
. Is it compatible withdcSkin
(bpp, etc)? UseOutputDebugString()
to see intermediate values / error codes. – i486