CClientDC dc(this);
CPen pen(1,2,RGB(0,0,255));
if(!m_dcMem.m_hDC)
{
m_dcMem.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(rect);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
m_dcMem.SelectObject(&bitmap);
m_dcMem.SelectObject(&pen);
m_dcMem.BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY); //必须加上此句
}
m_dcMem.MoveTo(100,200);
m_dcMem.LineTo(400,200);
在OnDraw将其贴出来:
void CFffasdView::OnDraw(CDC* pDC)
{
CFffasdDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetClientRect(&rect);
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&m_dcMem,0,0,SRCCOPY);
}