1 新建SDI应用程序,视图基类选择CScrollView
2 在资源视图里面导入一个位图资源
3 修改CSDI02182View::OnDraw函数
void CSDI02182View::OnDraw(CDC* pDC)
{
CSDI02182Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
CBitmap bmp;
CDC memDC;
CRect rect;
GetClientRect(&rect);
if (!bmp.LoadBitmapW(IDB_BITMAP1))
{
AfxMessageBox(_T("加载位图资源失败"));
return;
}
if (!memDC.CreateCompatibleDC(pDC))
{
AfxMessageBox(_T("创建内存DC失败"));
return;
}
memDC.SelectObject(&bmp);
BITMAP bitmap;
bmp.GetBitmap(&bitmap);
pDC->BitBlt(0, 0, bitmap.bmWidth, bitmap.bmHeight, &memDC, 0, 0, SRCCOPY);
CSize sizeTotal;
sizeTotal.cx = bitmap.bmWidth;
sizeTotal.cy = bitmap.bmHeight;
SetScrollSizes(MM_TEXT, sizeTotal);
}