3

在 c++ 中的 win32 中做一个项目,试图双缓冲正在绘制的图像,但我得到一个黑屏,上面绘制了正确的位图。这也导致了我的 WM_MOUSEMOVE 条件,它与光标一起拖动位图而不绘制位图。绘制代码如下:在WM_PAINT下的wndproc中调用paint(),scroll是滚动条的位置,目前未使用。

int paint(HWND hWnd, HINSTANCE hInst, RECT clientRect, std::vector<Measure> *measures, int scroll)
{
int x = 90;
hdc = BeginPaint(hWnd, &ps);
hdcmem = CreateCompatibleDC(hdc);
HBITMAP hbmScreen = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom);
SelectObject(hdcmem,hbmScreen); 
/*these functions just create the bitmaps into hdcmem*/
drawStaff(hWnd, hInst, clientRect, x, 0);
drawKey(hWnd, hInst, clientRect, x, (*measures)[0], 0);
drawTime(hWnd, hInst, clientRect, x, (*measures)[0], 0);
drawNotes(hWnd, hInst, clientRect, measures, x);
    BitBlt(hdc, 0, 0, clientRect.right, clientRect.bottom, hdcmem, 0, 0, SRCCOPY);
ReleaseDC(hWnd, hdcmem);
return 0;
}
4

1 回答 1

3

在绘制其他图形之前,您需要先使用背景颜色填充位图。如果我没记错的话,位图在创建时默认填充为黑色。

于 2012-01-16T03:12:58.273 回答