views:

111

answers:

2

Hi All, 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;
+1  A: 

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 to GetStockObject(NULL_BRUSH).

As a side note, you can use GetDC/ReleaseDC as long as you revalidate the invalid rectangle by calling ValidateRect.

avakar
A: 

I don't know if this answer is even relevant to C++, but to prevent flickering in .Net you also need to override the control's OnPaintBackground event.

MusiGenesis