CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(&rect);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
memDC.SelectObject(bitmap);
memDC.FillSolidRect(0,0,rect.Width(),rect.Height(),RGB(200,200,200));//画布为白色
//贴背景图
CDC picDC;
picDC.CreateCompatibleDC(&dc);
CString picPath=_T("D:\\test.bmp");
HBITMAP hbitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),picPath,
IMAGE_BITMAP,0,0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
CBitmap pic;
pic.Attach(hbitmap);
BITMAP bit;
pic.GetBitmap(&bit);
picDC.SelectObject(&pic);
memDC.BitBlt(0,0,bit.bmWidth,bit.bmHeight,&picDC,0,0,SRCCOPY);
... //memDC绘制其他图形
dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
picDC.DeleteDC();
pic.DeleteObject();
bitmap.DeleteObject();
memDC.DeleteDC();
MFC加载位图背景
最新推荐文章于 2022-09-22 13:28:37 发布