首先声明一个HBITMAP 成员m_hBmp;
还有BITMAP m_BitmapInfo;
在OnInitDialog里面
m_hBmp =(HBITMAP)LoadImage(AfxGetInstanceHandle(),strFile,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);//strFile是图片路径
GetObject(m_hBmp, sizeof(BITMAP), &m_hBmp);
然后在OnPaint函数里面(rect你自己定义一个矩形范围)
CPaintDC dc(this);
CDC dcImage;
if(!dcImage.CreateCompatibleDC(&dc)) return;
HBITMAP pOldBitmap = dcImage.SelectObject(&m_hBmp);
dc.StretchBlt(rect.left,rect.top,rect.right,rect.bottom,&dcImage,0,0,
m_hBmp.bmWidth,m_hBmp.bmHeight,SRCCOPY);
dcImage.SelectObject(pOldBitmap);
dcImage.DeleteDC();
//添加全局变量:
CBitmap m_bm;
CBrush m_br;
//在CMyDlg中先后初始化m_bm,m_br,即:
m_bm.m_hObject = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
_T("位图路径"), //如 "C:\\Documents and Settings\\ME\\桌面\\Bliss.bmp“
IMAGE_BITMAP,
0, 0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION);
m_br.CreatePatternBrush(&bm);
//最后 CMyDlg中重载虚拟函数OnCtlColor
将返回值hbr 改为你定义的m_br即可
PS: 我也是最近搞清楚的,还有不明白的相互交流哈