I am trying to implement double buffered drawing in a windows mobile application. But I still see the flickering. I am using InvalidateRect() in my rendering code(not shown here), instead of Updating the entire window. The rectangle mentioned in this API is flickering when I update/paint. Please help
case WM_PAINT:
{
hdc = BeginPaint(hWnd, &ps);
//hdc = GetDC(hWnd);
HDC newDC = CreateCompatibleDC(hdc);
HBITMAP hBitmap;
hBitmap = CreateCompatibleBitmap(hdc,width, height);
SelectObject(newDC,hBitmap));
BitBlt(hdc,0,0,width, height,newDC,0,0,SRCCOPY);
DeleteDC(newDC);
DeleteObject(hBitmap);
EndPaint(hWnd, &ps);
//ReleaseDC(hWnd,hdc); //Using this causes WM_PAIN fired without any reason.
}
break;
BeginPaint
erases background of the invalid rect, that's probably why you're seing flickering. If the class of the window in question is registered by you, you can set the background brush toGetStockObject
(NULL_BRUSH)
.As a side note, you can use
GetDC
/ReleaseDC
as long as you revalidate the invalid rectangle by callingValidateRect
.