Chinaunix首页 | 论坛 | 博客
  • 博客访问: 92398947
  • 博文数量: 19283
  • 博客积分: 9968
  • 博客等级: 上将
  • 技术积分: 196062
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-07 14:28
文章分类

全部博文(19283)

文章存档

2011年(1)

2009年(125)

2008年(19094)

2007年(63)

分类: C/C++

2008-05-18 20:25:51

  来源:

  然后在头文件中加入变量声明和函数声明:

以下是引用片段:

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();
来对象。


阅读(412) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~