<span style="font-size:18px;">MFC窗口贴图步骤:
1、创建位图:
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
2、创建兼容DC:
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);
3、将位图选入兼容DC中:
dcCompatible.SelectObject(&bitmap);
4、将兼容DC中的位图复制到原DC:
pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);
eg:
BOOL CGraphicView::OnEraseBkgnd(CDC* pDC) //窗口背景重绘时发送WM_ERASEBKGND消息
{
// TODO: Add your message handler code here and/or call default
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
BITMAP bmp;
bitmap.GetBitmap(&bmp);
CDC dcCompatible;
dcCompatible.CreateCompatibleDC(pDC);
dcCompatible.SelectObject(&bitmap);
CRect rect;
GetClientRect(&rect);
// pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,
0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
return TRUE;
// return CView::OnEraseBkgnd(pDC);
}
</span>
MFC:窗口贴图
最新推荐文章于 2023-01-08 12:23:20 发布