1、在OnDraw函数中修改如下:
void CBitmapView::OnDraw(CDC* pDC)
{CBitmapDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data hereCBitmap bitmap; //位图类对象bitmap.LoadBitmap(IDB_BITMAP1); //从资源中装载入位图CDC dcComp; //创建CDC对象dcComp.CreateCompatibleDC(pDC); //创建设备环境dcComp.SelectObject(&bitmap); //选择位图对象BITMAP bmInfo; bitmap.GetObject(sizeof(bmInfo),&bmInfo); //获取位图信息//将位图显示到视图中pDC->BitBlt(0,0,bmInfo.bmWidth,bmInfo.bmHeight, &dcComp, 0,0,SRCCOPY);}
2、运行效果如下: