Re: Why is OnPaint getting called while the redraw flag of the window is FALSE?
I'm not sure how WM_SETREDRAW is handled by the system. It may not prevent
WM_PAINT messages from being sent, but instead, window classes that support
the message may just set an internal flag and ignore WM_PAINT messages when
the flag is set.
You may want to do something similar since you're doing your own painting -
add a redraw flag and only do painting in response to WM_PAINT if the flag
is not set.
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
"Timo Partanen" <timo.partanen@motivesys.com> wrote in message
news:ODKdcB$YIHA.984@TK2MSFTNGP06.phx.gbl...
Hi,
I have a list control that derives from CListCtrl. I noticed that my
OnPaint (i.e. the system sends a WM_PAINT message) is getting called while
the redraw flag of the window is FALSE. This temporarily results in a
black display for the window. When the system sends another WM_PAINT for
the window, the display starts looking OK again as the redraw flag of the
window is TRUE. This sequence results in a flickering effect that I would
definitely want to avoid. Is it okay that OnPaint is getting called while
the redraw flag of the window is FALSE? If yes, what should WM_PAINT
processing do in that case?
My OnPaint handler:
---
CPaintDC dc( this ); // Device context for painting.
// Get clip and client rectangle.
CRect rectClient;
CRect rectClip;
dc.GetClipBox( &rectClip );
GetClientRect( &rectClient );
// Create a compatible memory DC.
dcMem.CreateCompatibleDC( &dc );
CBitmap bitmap;
bitmap.CreateCompatibleBitmap( &dc,
ectClient.Width(), rectClient.Height() );
CBitmap* pbitmapOld = dcMem.SelectObject( &bitmap );
// Let the control do its default drawing.
CWnd::DefWindowProc( WM_PAINT, ( WPARAM )dcMem.m_hDC, 0 );
// Here I do my own drawing.
// .
// .
// .
// My own drawing ends.
// Bit-block-transfer the contents of the memory DC to the original DC.
dc.BitBlt( rectClip.left, rectClip.top,
rectClip.Width(), rectClip.Height(),
&dcMem, rectClip.left, rectClip.top, SRCCOPY );
---
If I change my code to be as below, the problem disappears. Can someone
say or guess why?
---
CPaintDC dc( this ); // Device context for painting.
// Let the control do its default drawing.
CWnd::DefWindowProc( WM_PAINT, ( WPARAM )dcMem.m_hDC, 0 );
// Here I do my own drawing.
// .
// .
// .
// My own drawing ends.
---
One thing that might affect is that the list-view control has the
LVS_EX_DOUBLEBUFFER extended style.
Thanks in advance.
Timo Partanen