在vs2005中使用MFC,怎样在基于对话框的的程序中将位图作为对话框的背景。
展开全部
首先声明一个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();
还有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: 我也是最近搞清楚的,还有不明白的相互交流哈
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: 我也是最近搞清楚的,还有不明白的相互交流哈
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询