用 c++ 在 win32 中做一个项目,试图对正在绘制的图像进行双重缓冲,但我得到一个黑屏,上面绘制了正确的位图。这也导致了我的 WM_MOUSEMOVE 条件,该条件将位图与光标一起拖动以不绘制位图。 paint的代码如下:paint()在WM_PAINT下的wndproc中调用,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;
}
最佳答案
在绘制其他图形之前,您需要先用背景颜色填充位图。如果没记错的话,位图在创建时默认填充为黑色。
关于c++ - Win32 双缓冲绘图黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8875395/