我在OnInitDialog()中用下列语句来加载一个指定的位图并把它作为对话框的背景,但是总是显示不出来,高手帮忙看看阿
char szPath[200];
memset(szPath,0,sizeof(szPath));
GetCurrentDirectory(sizeof(szPath),szPath);
CString strPath;
strPath = szPath;
strPath = strPath + "\\首页背景.bmp";
RECT DlgRect;
GetClientRect(&DlgRect);
int cx = DlgRect.right- DlgRect.left;
int cy = DlgRect.bottom- DlgRect.top; CDC dcMem;
CDC *pDC = GetDC();
// CClientDC m_dc(this);
CBitmap bitmap;
HBITMAP hbmpOld;
hbmpOld=(HBITMAP)LoadImage(0,strPath,IMAGE_BITMAP,cx,cy,LR_LOADFROMFILE);
// 设定位图的高和宽(cx,cy)
bitmap.Attach(hbmpOld);
BITMAP bmp;
bitmap.GetBitmap(&bmp);
dcMem.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMem.SelectObject(&bitmap);
pDC->BitBlt(0,0,cx,cy,&dcMem,0,0,SRCCOPY);
dcMem.SelectObject(pOldBitmap);
DeleteObject(bitmap.Detach());
char szPath[200];
memset(szPath,0,sizeof(szPath));
GetCurrentDirectory(sizeof(szPath),szPath);
CString strPath;
strPath = szPath;
strPath = strPath + "\\首页背景.bmp";
RECT DlgRect;
GetClientRect(&DlgRect);
int cx = DlgRect.right- DlgRect.left;
int cy = DlgRect.bottom- DlgRect.top; CDC dcMem;
CDC *pDC = GetDC();
// CClientDC m_dc(this);
CBitmap bitmap;
HBITMAP hbmpOld;
hbmpOld=(HBITMAP)LoadImage(0,strPath,IMAGE_BITMAP,cx,cy,LR_LOADFROMFILE);
// 设定位图的高和宽(cx,cy)
bitmap.Attach(hbmpOld);
BITMAP bmp;
bitmap.GetBitmap(&bmp);
dcMem.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = dcMem.SelectObject(&bitmap);
pDC->BitBlt(0,0,cx,cy,&dcMem,0,0,SRCCOPY);
dcMem.SelectObject(pOldBitmap);
DeleteObject(bitmap.Detach());
说的对,但是我看了他的代码,我觉得这辆句代码:
BITMAP bmp;
bitmap.GetBitmap(&bmp);
好像在这里没有什么用阿,另外好像CDC *pDC = GetDC();
也纯粹是多余的。不知对否?