void CtstView::OnDraw(CDC* pDC)
{
pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
// return;
// TODO: add draw code for native data here
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
bmpBackground.LoadBitmap(IDB_BITMAP3);
//IDB_BITMAP3是你自己的图对应的ID
BITMAP bitmap;
bmpBackground.GetBitmap(&bitmap);
CBitmap *pbmpOld=dcMem.SelectObject(&bmpBackground);
//dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY); //CtstDoc*
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitmap.bmWidth,bitmap.bmHeight,SRCCOPY);
}
本文介绍了一个使用MFC框架进行窗口绘图的例子。通过创建兼容设备上下文并加载位图资源,实现了将指定的背景图片绘制到视图窗口的过程。代码详细展示了如何通过CDC成员函数StretchBlt进行拉伸绘制。
5464

被折叠的 条评论
为什么被折叠?



