MyDemo located on G:\MY_PRO_2015\BKImg_Demo
1.VC6 new a Projects:MFC AppWizard(exe) type:Dialog based
2.Surfing on the Internet.
(1)http://blog.sina.com.cn/s/blog_6f83fdb40100tgi3.html
第一种方式:资源位图的方式(背景图片只能是bmp格式,双缓存方式绘制防止闪烁)
需要先把以"bmp"为后缀的图片通过插入资源的方式添加到工程中,然后调用下面的函数即可
第二种方式:借用控件IPicture加载图片的方式(背景图片可以是jpg格式)
(2) http://www.cnblogs.com/xiao-cheng/archive/2012/01/17/2325114.html
VC++中如何给对话框加背景图片
Well, For me , both of the methods have failed.
(3) The third one:http://blog.sina.com.cn/s/blog_4ac0eb8101010ico.html
(3.1)//背景图片信息 add on Dlg.h
IPicture *m_picture;
OLE_XSIZE_HIMETRIC m_width;
OLE_YSIZE_HIMETRIC m_height;
BOOL m_IsShow;
(3.2) add on Dlg.cpp-- OnPaint():
else{
CPaintDC dc(this);
CFile m_file("D:\\1.jpg",CFile::modeRead );
//获取文件长度
DWORD m_filelen = m_file.GetLength();
//在堆上分配空间
HGLOBAL m_hglobal = GlobalAlloc(GMEM_MOVEABLE,m_filelen);
LPVOID pvdata = NULL;
//锁定堆空间,获取指向堆空间的指针
pvdata = GlobalLock(m_hglobal);
//将文件数据读区到堆中
m_file.ReadHuge(pvdata,m_filelen);
IStream* m_stream;
GlobalUnlock(m_hglobal);
//在堆中创建流对象
CreateStreamOnHGlobal(m_hglobal,TRUE,&m_stream);
//利用流加载图像
OleLoadPicture(m_stream,m_filelen,TRUE,IID_IPicture,(LPVOID*)&m_picture);
m_stream->Release();
m_picture->get_Width(&m_width);// 宽高,MM_HIMETRIC 模式,单位是0.01毫米
m_picture->get_Height(&m_height);
m_IsShow = TRUE;
m_file.Close();
if (m_IsShow==TRUE)
{
CRect rect;
GetClientRect(rect);
int nW, nH;
nW = (int)(rect.Width());
nH = (int)(rect.Height());
m_picture->Render(dc,0,0,nW,nH,0,m_height,m_width,-m_height,&rect);
}
CDialog::OnPaint();
}//end -else
【Release版本,bkimg和exe放到一起,更换jpg,下次启动exe,背景图片自动更换。】