Win32 Double Buffering drawing black background

2.8k views Asked by At

Doing a project in win32 in c++, attempting to double buffer the image being drawn, but I'm getting a black screen with the correct bitmaps drawn over it. This is also causing my WM_MOUSEMOVE condition, which drags a bitmap along with your cursor to not draw the bitmap. Code for paint is below: paint() is called in wndproc under WM_PAINT, scroll is the position of the scroll bar, unused so far.

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;
}
1

There are 1 answers

3
hypercode On BEST ANSWER

You need to fill the bitmap with whatever your background color is first before drawing your other graphics. If memory serves me correctly, bitmaps are filled with black by default when they are created.