Update WM_PAINT and Memory DC
-
Hi All , I have a code :
int CExWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct)==-1) return -1;
CClientDC dc(this);
pDC.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc,Width,Height);
pDC.SelectObject(&bitmap);
return 0;
}
void CExWnd::OnPaint()
{
CClientDC dc(this); // here
Draw ( pDC ) ;
dc.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY);
}This is a example . I have a question . Why WM_PAINT auto update when compatible with pDC . ( the same CClientDC ) . I'm not good at English . Sorry !! Thanks .
-
Hi All , I have a code :
int CExWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if(CWnd::OnCreate(lpCreateStruct)==-1) return -1;
CClientDC dc(this);
pDC.CreateCompatibleDC(&dc);
bitmap.CreateCompatibleBitmap(&dc,Width,Height);
pDC.SelectObject(&bitmap);
return 0;
}
void CExWnd::OnPaint()
{
CClientDC dc(this); // here
Draw ( pDC ) ;
dc.BitBlt(0,0,Width,Height,&pDC,0,0,SRCCOPY);
}This is a example . I have a question . Why WM_PAINT auto update when compatible with pDC . ( the same CClientDC ) . I'm not good at English . Sorry !! Thanks .
-
The underlying DC in your CClientDC is where the drawing gets visible. You can use temporary DC's to do painting, but then you will have to transfer it to the 'visual' DC. That's what the BitBlt call is doing.
-
It is indeed really weird. It looks like CClientDC directly or indirectly causes window to redraw in turn causing constant flow of WM_PAINT messages. Even wierder, you can remove BitBlt from OnPaint and window will still redraw, providing your code is equivalent to mine. This is a toughest question I have ever encountered on many discussion forums. I have quickly tested your code on Vista and so far I did not find any answers. I am looking into it and when (if) I find and answer it will be a real satisfaction. Later, I am also going to test it on XP and Windows 7.
JohnCz MS C++ MVP