GDI+配置(vs2008)

1 在项目属性中添加GDI+静态库链接

打开项目,选择【项目】——》【XXX属性】(XXX为当前项目名称),打开“项目属性”对话框,展开“属性配置”,选择“连接器”下的“输入”,然后在”依赖附加项“中添加“gdiplus.lib”

2 添加必要的代码

(1)打开“解决方案资源管理器”,打开stdafs。h文件,添加代码如下:

#include "gdiplus.h"
using namespace Gdiplus;
(2)打开类视图 选中相应的应用程序类CXXXApp 为其添加两个成员变量

 GdiplusStartupInput m_GdiplusStartupInput;
 ULONG_PTR m_GdiplusToken;

(3)在CXXXApp类的InitInstance函数中添加

//GDI+图像库初始化
 GdiplusStartup(&m_GdiplusToken,&m_GdiplusStartupInput,NULL);

(4)重写CXXXApp类的ExitInstance函数

 

int CBMPProApp::ExitInstance(void)
{
 
 //关闭gdi+图像库
 GdiplusShutdown(m_GdiplusToken);
 return CWinApp::ExitInstance();
}

//以下假设你已经配置好VC6的GDI+环境 1.新建一个基于CScrollView的单文档程序, 2.在stdafx.h内添加如下代码: #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif #include "GdiPlus.h" using namespace Gdiplus; #pragma comment(lib,"gdiplus.lib") 3.在GdiApp.h里的CGdiAppApp中加入两个成员: GdiplusStartupInput m_gdiplusStartupInput;// ULONG_PTR m_pGdiToken;// 4.在GdiApp.cpp中的CGdiAppApp构造函数CGdiAppApp()添加如下代码: GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL);// 5.在GdiApp.h里给CGdiAppApp添加一个析构函数~CGdiAppApp(); 6.在GdiApp.cpp中添加CGdiAppApp的析构函数~CGdiAppApp(): CGdiAppApp::~CGdiAppApp()// { GdiplusShutdown(m_pGdiToken);// } 7.在GdiAppView.h的CGdiAppView中添加成员变量: Bitmap* m_pbmp; 并在GdiAppView.cpp中的GdiAppView构造函数和析构函数中添加如下代码: CGdiAppView::CGdiAppView():m_pbmp(0)// { // TODO: add construction code here } CGdiAppView::~CGdiAppView() { delete m_pbmp;// m_pbmp=0;// } 8.按Ctrl+W,在弹出的对话框里选择Message Maps选项卡 class name选择CGdiAppView Object IDs里选中ID_FILE_OPEN 然后在Message里双击COMMAND 弹出的对话框选择Ok 这时会在Member functions:里多出一条刚添加进去的消息映射函数 双击它会自动跳转进入GdiAppView.cpp中的void CGdiAppView::OnFileOpen()函数处 然后添加如下代码: void CGdiAppView::OnFileOpen() { //见源码处 } 9.为了使8处代码有用,还需要: 在GdiAppView.h里添加两个函数声明: int A2U(const char* szA,wchar_t* szU,size_t cnt);// std::wstring A2U(const char* szA);// 并#include 然后在GdiAppView.cpp里加入这两个函数的实现 10.在GdiAppView.cpp中的OnDraw函数中添加显示代码: void CGdiAppView::OnDraw(CDC* pDC) { //见源码处 } 11.结束.有问题联系hastings1986@163.com //可能你Debug版本编译不过,则打开Gdi+的头文件GdiPlusBase.h //并修改为如下(其实就加了两个重载版本的new和delete): #ifndef _GDIPLUSBASE_H #define _GDIPLUSBASE_H class GdiplusBase { public: void (operator delete)(void* in_pVoid) { DllExports::GdipFree(in_pVoid); } void* (operator new)(size_t in_size) { return DllExports::GdipAlloc(in_size); } void (operator delete[])(void* in_pVoid) { DllExports::GdipFree(in_pVoid); } void* (operator new[])(size_t in_size) { return DllExports::GdipAlloc(in_size); } //////////////////////////////// void* (operator new)(size_t in_size,
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值