我正在使用C++在Win32环境下进行项目开发,尝试实现双缓冲绘图,但是屏幕上只显示黑色背景,并且正确的位图也无法显示。这也导致我的WM_MOUSEMOVE事件无法将位图随光标移动而绘制。下面是paint()函数的代码:paint()被调用于wndproc下的WM_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;
}
WM_CREATE
(和WM_SIZE
)时制作一次,并使用SetWindowLongPtr(GWLP_USERDATA)
将其附加到HWND
上。 - Necrolis