Why do my Controls flicker ? (src incl.)
-
In my VS8 MFC Dialog exploratory-app, the listbox and OK buttons flicker. I've tried the Double Buffer code (http://www.codeproject.com/bitmap/drawing_without_flicker.asp[^]) like this:
void CFlickerTestDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClient; GetClientRect(rcClient); // See Note 1 CDC MemDC,*pDC; CBitmap MemBitmap; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); MemBitmap.CreateCompatibleBitmap(pDC,rcClient.right,rcClient.bottom); CBitmap *pOldBitmap = MemDC.SelectObject(&m_BmpTarget); //CBrush bkBrush(HS_FDIAGONAL,RGB(0,rand()%255,0)); // See Note 2 //MemDC.FillRect(rcClient,&bkBrush); pDC->BitBlt(0,0,rcClient.right,rcClient.bottom,&MemDC,0,0,SRCCOPY); //See Note 3 MemDC.SelectObject(pOldBitmap); }
but that didn't help, the listbox and OK buttons still flicker. (also, I don't understand why my static image is covered up by some grey layer - but my main priority is the annoying flicker) I've uploaded my project (255KB) here in a .zip: http://www.webfilehost.com/?mode=viewupload&id=4066339[^] There's a countdown timer on the bottom-right of the page that changes to a download link (I don't have any online webspace to share files so I had to resort to one of these free sharing services) I'd be SO grateful for any help -
In my VS8 MFC Dialog exploratory-app, the listbox and OK buttons flicker. I've tried the Double Buffer code (http://www.codeproject.com/bitmap/drawing_without_flicker.asp[^]) like this:
void CFlickerTestDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rcClient; GetClientRect(rcClient); // See Note 1 CDC MemDC,*pDC; CBitmap MemBitmap; pDC = this->GetDC(); // Get Current DC MemDC.CreateCompatibleDC(pDC); MemBitmap.CreateCompatibleBitmap(pDC,rcClient.right,rcClient.bottom); CBitmap *pOldBitmap = MemDC.SelectObject(&m_BmpTarget); //CBrush bkBrush(HS_FDIAGONAL,RGB(0,rand()%255,0)); // See Note 2 //MemDC.FillRect(rcClient,&bkBrush); pDC->BitBlt(0,0,rcClient.right,rcClient.bottom,&MemDC,0,0,SRCCOPY); //See Note 3 MemDC.SelectObject(pOldBitmap); }
but that didn't help, the listbox and OK buttons still flicker. (also, I don't understand why my static image is covered up by some grey layer - but my main priority is the annoying flicker) I've uploaded my project (255KB) here in a .zip: http://www.webfilehost.com/?mode=viewupload&id=4066339[^] There's a countdown timer on the bottom-right of the page that changes to a download link (I don't have any online webspace to share files so I had to resort to one of these free sharing services) I'd be SO grateful for any helpThe code you posted does nothing to prevent flicker. I've been through your code and made some modifications to fix the flicker. Having a picture control behind all the other controls is the problem. It prevents you from clipping the other controls to prevent flicker. I added the WS_CLIPCHILDREN style to the dialog, deleted the picture control from the dialog's resource, and instead draw the bitmap to the window in response to WM_ERASEBKGND. This way, Windows automagically clips all the child controls, so you don't have to redraw them on every timer event. Shoot me an email here and I'll send the changes in a reply. BTW, the code leaks GDI resources on every timer event :) I didn't look for those leaks. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java: