`
isiqi
  • 浏览: 16082720 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

在MFC程序中显示JPG/GIF图像

阅读更多

  在“E:\兴辉俊武\vc++学习笔记\动画图片操作\JPG图像加载及超连接”定义了所需的类
  CPictureCtrl使你可以在任何对话框或窗口中把图像作为子窗口显示。
  例如:关于对话框中加载IDC_MYIMAGE图像
  classCAboutDialog:publicCDialog{
  protected:
  CPictureCtrlm_wndPict;
  virtualBOOLOnInitDialog();
  };
  BOOLCAboutDialog::OnInitDialog()
  {
  m_wndPict.SubclassDlgItem(IDC_MYIMAGE,this);//IDC_MYIMAGE和变量m_wndPict建立联系
  returnCDialog::OnInitDialog();
  }
  在文档/视图中加载JPG/GIF图像
  在doc.h中
  #pragmaonce
  #include"Picture.h"
  protected:
  CPicturem_pict;
  public:
  CPicture*GetPicture(){
  return&m_pict;
  doc.cpp
  #include<afxdisp.h>
  #include<afxpriv2.h>
  voidCPictureDoc::Serialize(CArchive&ar)//打开图片在文档中显示
  {
  if(ar.IsLoading()){
  VERIFY(m_pict.Load(ar));
  }else{}
  }
  BOOLCPictureDoc::OnNewDocument()/*为了使程序更实用,CPictureDoc::OnNewDocument从程序资源数据加载了一幅图像。为了显示这幅图像,CPictureView::OnDraw要调用CPicture::Render。这样程序一启动便会显示一幅默认的图像。*/
  {
  m_pict.Load(IDR_MAINFRAME);
  returnTRUE;
  }
  voidCPictureView::OnDraw(CDC*pDC)
  {
  CPictureDoc*pDoc=GetDocument();
  ASSERT_VALID(pDoc);
  CPicture*ppic=pDoc->GetPicture();
  ASSERT(ppic);
  if(*ppic){
  CRectrc;
  GetImageRect(rc);//GetImageRect是CPictureView类的一个成员函数
  ppic->Render(pDC,rc);
  }
  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics