nav-left cat-right
cat-right
Blog > Blog > C++ > MFC > Flicker Free example with dialog

Flicker Free example with dialog

One can find several examples for flicker free drawing in MFC. (see for example Flicker Free Drawing In MFC)

Here is an example done by myself. I used the CMemDC Class posted in Enhanced CMemDC.

The example code for download:

  FlickerFreeDemoBackground.zip (27.7 KiB)

What is the magic? We need to make sure, that the background of our window is not painted when OnPaint is called. For that we need to include the message ON_WM_ERASEBKGND() with the simple content in its function

BOOL CFlickerFreeDemoDlg::OnEraseBkgnd(CDC* pDC)
{
	return FALSE;
}
The painting is triggered with a timer initialised in OnInitDialog()
BOOL CFlickerFreeDemoDlg::OnInitDialog()
{
	SetTimer(1, 33, NULL);
...
with
void CFlickerFreeDemoDlg::OnTimer(UINT nIDEvent) 
{
	PixelArray.IterateNewContent();
	UpdatePlot();
}
Updateplot() is used to invalidate the window and trigger the OnPaint message
void CFlickerFreeDemoDlg::UpdatePlot()
{		
	Invalidate();
	UpdateWindow();	
}

Pages: 1 2 3

3 Responses to “Flicker Free example with dialog”

  1. [...] It works very similar to the description of Flicker Free example with dialog. [...]

  2. Maximus sagt:

    I would like to see a continuation of the topic

  3. What exactly do you want to see?

Leave a Reply

Spam Protection by WP-SpamFree