1 新建单文档MFC工程ShowBMP,指定视图的基类为CScrollView
2 添加位图资源
3 修改CShowBMPView的OnDraw()方法
void CShowBMPView::OnDraw(CDC* pDC)
{
CShowBMPDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CBitmap bmp;
CDC memDC;
CRect rect;
GetClientRect(&rect);
if (!bmp.LoadBitmap(IDB_BITMAP2))
{
AfxMessageBox("加载位图失败");
return;
}
if (!memDC.CreateCompatibleDC(pDC))
{
AfxMessageBox("创建内存DC失败");
return;
}
memDC.SelectObject(&bmp);
pDC->BitBlt(0, 0, rect.right, rect.Width(), &memDC, 0, 0, SRCCOPY);
BITMAP bitmap;
bmp.GetBitmap(&bitmap);
CSize sizeTotal;
sizeTotal.cx = bitmap.bmWidth;
sizeTotal.cy = bitmap.bmHeight;
SetScrollSizes(MM_TEXT, sizeTotal);
}