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;
} |
BOOL CFlickerFreeDemoDlg::OnEraseBkgnd(CDC* pDC)
{
return FALSE;
}
The painting is triggered with a timer initialised in
OnInitDialog()
BOOL CFlickerFreeDemoDlg::OnInitDialog()
{
SetTimer(1, 33, NULL);
... |
BOOL CFlickerFreeDemoDlg::OnInitDialog()
{
SetTimer(1, 33, NULL);
...
with
void CFlickerFreeDemoDlg::OnTimer(UINT nIDEvent)
{
PixelArray.IterateNewContent();
UpdatePlot();
} |
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();
} |
void CFlickerFreeDemoDlg::UpdatePlot()
{
Invalidate();
UpdateWindow();
}
Ähnliche Beiträge
What exactly do you want to see?
I would like to see a continuation of the topic