我在主窗口的 WM_PAINT 消息处理程序中有以下代码:
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 );
};
我也会在皮肤上绘制文本,这就是为什么我使用内存位图在内存 DC 上进行 BitBlt ing,我也尝试过直接绘制(直接到 hdc),但没有奏效,我不知道如何调试它。我唯一能检查的是在 LoadBitmap 函数的返回值和 void BossController::paint (HWND hwnd, HBITMAP skin) 中检查皮肤是否为 NULL。还有BitBlt的返回值。
它总是显示一个带有我在创建窗口时选择的背景颜色的矩形。(窗口是自定义皮肤的,所以没有标题栏等。
有人可以指出错误(如果有的话)或潜在的陷阱,或者如何调试它?