VC6如何使用VS2005中的CImage类功能

来源:互联网 发布:公司取名软件crsky 编辑:程序博客网 时间:2024/05/17 09:15
VC6如何使用VS2005中的CImage类功能 

   由于VC6启动速度快,产生的执行代码小,还有可爱的类向导,所以许多C++程序员还工作在VC6环境中。
      但是我们想在VC6中用VS2005中的新功能怎么办呢?例如CImage类(有很强的图像处理功能).当然我们无法直接使用CImage了,经过我的思考和实践,以下方法是可行的:
        用VS2005生成一个CImage2005动态库,然后用VC6调用就可以了。
DLL主要代码如下:
//Image2005.h
#pragma once
class AFX_EXT_CLASS CImage2005//导出整个类
{
private:
 void *m_pImage;
public:
 CImage2005(void);
 inline HRESULT Load( LPCTSTR pszFileName );
 inline BOOL IsNull();
 inline BOOL Draw( HDC hDestDC, const RECT& rectDest );
public:
 virtual ~CImage2005(void);
};
//Image2005.cpp
#include "StdAfx.h"
#include "Image2005.h"
#include "atlimage.h"

CImage2005::CImage2005(void)
{
 m_pImage=NULL;
 m_pImage=new CImage;
}

CImage2005::~CImage2005(void)
{
 if(m_pImage)
 {
  delete m_pImage;
  m_pImage=NULL;
 }
}
inline HRESULT CImage2005::Load( LPCTSTR pszFileName )
{
 return ((CImage*)m_pImage)->Load(pszFileName);
}
inline BOOL CImage2005::IsNull()
{
 return ((CImage*)m_pImage)->IsNull();
}
inline BOOL CImage2005::Draw( HDC hDestDC, const RECT& rectDest )
{
 return ((CImage*)m_pImage)->Draw(hDestDC,rectDest );
}
//如果你想用什么功能,自己添加就是了。这样在VC6下就可以用CImage2005代替CImage了:
CImage2005 m_image;
m_image.Load("登陆界面.jpg");
if (m_image.IsNull())
{
  MessageBox("找不到背景图片文件","提示",MB_ICONWARNING);
}
void CXXXView::OnDraw(CDC* pDC) 
{
 //////////////////////////////////////////////////////////////////////////
 if (!m_image.IsNull())//贴图
 {
  CRect rect;
  GetClientRect(&rect);
  m_image.Draw(pDC->m_hDC,rect);
 }
 //////////////////////////////////////////////////////////////////////////
}//经过测试成功!
//OK,是不是达到我们的愿望了,用上述办法就可以将VC2005中的许多重要功能用在VC6中,从而避免为了一个功能不得不从VC6转到.net的尴尬。
原创粉丝点击