使用双缓冲绘图时出现错误!
按:http://community.csdn.net/Expert/topic/3119/3119399.xml?temp=.4067957
使用了双缓冲,但是不知道为什么我的代码出现如下错误:
=======================================================
应用程序发生异常 unknown software exception(0x80000003),位置0x77f813b1.
========================================================
源代码如下:
/////////////////////////////////////////////////////////////////////////////
// CFootBallGMView drawing
void CFootBallGMView::OnDraw(CDC* pDC)
{
CFootBallGMDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CDC MemDC;
CBitmap MemBitmap;
//CRectangle rect;
CRect rc;
GetClientRect( rc );
int nWidth, nHeight; // 取用户区大小
nWidth = rc.Width();
nHeight = rc.Height();
MemDC.CreateCompatibleDC( NULL );
MemBitmap.CreateCompatibleBitmap( pDC, nWidth, nHeight );
CBitmap *pOldBit = MemDC.SelectObject( &MemBitmap );
MemDC.FillSolidRect( 0, 0, nWidth, nHeight, RGB(255, 255, 255) );
POINT point;
POINT lpoint;
point.x = 100;
point.y = 100;
lpoint.x = 200;
lpoint.y = 200;
while(1)
{
Invalidate();
MemDC.MoveTo( point );
MemDC.LineTo( lpoint );
pDC->BitBlt(0,0,nWidth,nHeight,&MemDC,0,0,SRCCOPY);
MemBitmap.DeleteObject();
MemDC.DeleteDC();
}
}