MFC改个背景色,真麻烦,找了段代码:
void CTestBmpDlg::OnPaint()
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackGround;
bmpBackGround.LoadBitmap(IDB_BITMAP8);//IDB_BITMAP8是加载的BMP资源号
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);
return;
}
做个记号,下次好用,这只是使用BMP图片,如何直接使用png图片再研究研究。
继续上次研究加载PNG和JPG图片做背景
void CTestImageDlg::OnPaint()
{
CImage img;
HRESULT ret = img.Load(_T("res/1.png")); //wuziqi.png是我要加载的图片名称,包含路径
HBITMAP hbitmap = img.Detach();
//像操作 BMP 图片一样处理图片 ,下面是显示图片的操作
CPaintDC pDC(this);
CBitmap cBitmap;
BITMAP bitmap;
CDC memdc;
cBitmap.Attach(hbitmap);
memdc.CreateCompatibleDC(&pDC);
memdc.SelectObject(hbitmap);
cBitmap.GetBitmap(&bitmap);
CRect rect;
GetClientRect(&rect);
pDC.StretchBlt(0,0,rect.Width(),rect.Height(),&memdc,0,0,rect.Width(),rect.Height(),SRCCOPY);
return;
}