BOOL LoadMyJpegFile(CString fname,LPPICTURE *lppi);
LPPICTURE m_lppi;//加载图像文档的流
BOOL m_bHadLoad;//已加载了背景图像
然后在OnPaint函数中加入: if(m_bHadLoad)
{
CDC *pDC=GetDC();
CRect rc;
long hmWidth=0;
long hmHeight=0;
m_lppi->get_Height(&hmHeight);
m_lppi->get_Width(&hmWidth);
GetClientRect(&rc);
int nWidth,nHeight;
nWidth=rc.Width();
nHeight=rc.Height();
HRESULT hr=m_lppi->Render(pDC->m_hDC,nWidth,0,-nWidth,nHeight, hmWidth,hmHeight,-hmWidth,-hmHeight,&rc);
}
在OnInitDialog函数中这样调用上面的加载函数: TCHAR strPath[MAX_PATH];
memset(strPath,0,MAX_PATH);
GetCurrentDirectory(MAX_PATH,strPath);
wcscat_s(strPath,MAX_PATH,_T("\\a_bear.jpg"));
m_bHadLoad=LoadMyJpegFile(strPath,&m_lppi);
就能够显示jpg图片了,最后要记得在OnDestroy函数中加入: m_lppi->Release();
来释放对象。
|