直接在设备上下文DC中作图;
void CGdiBitmapView::OnPaintBitmap()
{
// TODO: Add your command handler code here
//取得DC设备
CDC *pDC = GetDC();
//保存DC状态
int nOldDC = pDC->SaveDC();
//获取客户区大小
RECT rect;
GetClientRect(&rect);
//创建与DC兼容的Bitmap
m_pViewBitmap->CreateCompatibleBitmap(pDC, rect.right, rect.bottom);
//选择Bitmap到DC中
pDC->SelectObject(m_pViewBitmap);
//背景填充为紫红色
pDC->FillSolidRect(&rect, 333) ;
//画图
POINT startPoint;
startPoint.x = 0;
startPoint.y = 0;
POINT endPoint;
endPoint.x = rect.right;
endPoint.y = rect.bottom;
pDC->MoveTo(startPoint);
pDC->LineTo(endPoint);
//释放DC资源
pDC->RestoreDC(nOldDC);
ReleaseDC(pDC);
}void CGdiBitmapView::OnPaintBi