比如有下面一个应用:
在一个对话框内,我希望通过点击按钮来改变按钮右侧显示的图片,图片是Gif格式的。如何才能显示该图像?是要放置在picture control中吗?怎么放进去阿?

解决方案 »

  1.   

    使用GDI+  打开文件  
         Image   *pImage;  
       
      CFileDialog   dlg(TRUE   ,   "BMP"   ,   NULL   ,   OFN_HIDEREADONLY   |   OFN_OVERWRITEPROMPT   ,  
      "Images   File(*.BMP;*.JPG;*.GIF;*.PNG;*.TIF;*.WMF;*.EMF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIF;*.WMF;*.EMF||"   ,this);  
      if(dlg.DoModal()   ==   IDOK)  
      {  
          m_strOpenFileName   =   dlg.GetPathName();  
          if(m_strOpenFileName.GetLength()   >   3)  
      {  
      WCHAR   szFileNameW[MAX_PATH];  
      char   szFileNameA[MAX_PATH];  
      strcpy(szFileNameA   ,   m_strOpenFileName.GetBuffer(m_strOpenFileName.GetLength()));  
      m_strOpenFileName.ReleaseBuffer();  
      MultiByteToWideChar(CP_ACP,   0,   szFileNameA,  
      strlen(szFileNameA)+1,   szFileNameW,        
      sizeof(szFileNameW)/sizeof(szFileNameW[0]));  
       
      Image   image(szFileNameW);  
      pImage   =   image.Clone();  
      Invalidate();  
      }  
      }  
       
      显示  
      OnDraw  
      if(pImage)  
      {  
      Graphics   graphics(pDC->GetSafeHdc());  
      Rect   rt;  
      RECT   rc;  
      GetClientRect(&rc);  
      rt.X   =   rc.left;  
      rt.Y   =   rc.top;  
      rt.Width   =   rc.right   -   rc.left;  
      rt.Height   =   rc.bottom   -   rc.top;  
      int   nX,nY;  
      if((int)pImage->GetWidth()   >=   rt.Width)  
      {  
      nX   =   0;  
      }  
      else  
      {  
      nX   =   (rt.Width   -   pImage->GetWidth())   /   2;  
      }  
      if((int)pImage->GetHeight()   >=   rt.Height)  
      {  
      nY   =   0;  
      }  
      else  
      {  
      nY   =   (rt.Height   -   pImage->GetHeight())   /   2;  
      }  
       
      graphics.DrawImage(pImage   ,   nX   ,   nY   );  
       
      }
      

  2.   

    看来这个问题确实是基础阿。。我现在解决了,,我是利用Visual Studio的工作环境中,通过修改picture control的属性完成的。谢谢。