在C++中做win32項目,嘗試對正在繪製的圖像進行雙緩衝,但是我得到一個黑色的屏幕,並在其上繪製了正確的位圖。這也會導致我的WM_MOUSEMOVE條件,該條件拖動位圖和光標一起不繪製位圖。繪製代碼如下:paint()在WM_PAINT下的wndproc中調用,scroll是滾動條的位置,目前尚未使用。Win32雙緩衝繪製黑色背景
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;
}
你不應該在你繪製的時候重新制作backbuffer,只需在WM_CREATE(和WM_SIZE)上創建一次,然後用'SetWindowLongPtr(GWLP_USERDATA)'將它附加到'HWND'上。 – Necrolis 2012-01-16 07:23:14
你有一個資源泄漏 - 你忘了在從這個函數返回之前調用hdcmem上的DeleteObject。 – selbie 2012-01-16 08:23:59
你也沒有打電話給EndPaint。 – selbie 2012-01-16 08:26:21