vs2005 初始化GDI+环境
2011-07-21 17:32
169 查看
第一步:建立新的GdiNew.h头文件,并将其包含在stdafx.h中
在stdafx.h包含GdiNew.h
第二步: 在类中添加成员变量
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
第三步: 在类的初始化Init()中添加
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
第四步: 在销毁函数ExitInstance()或类析构函数中添加
GdiplusShutdown(gdiplusToken);
................................................................................................
................................................................................................
可能出现的一些问题:
在第一步: 在stdafx.h头文件中 加入gdi+头文件时
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
注意: 这样有时可能会跳出106个错误
类似 error C2146: 语法错误 : 缺少“;”(在标识符“GraphicsState”的前面)
error C2065: “META_SETBKCOLOR”: 未声明的标识符
原因:gdi+ 头文件中的一些宏定义未声明
解决方法: 在 #inclue<gdiplus.h>前 加入新的头文件 #include<afxdtctl.h> 即用如下代码:
#include <afxdtctl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
以下为网上资料 : 在SDI单文档程序中,如何使用GDI+
1
2
3
4
5
在GdiApp.cpp中添加CGdiAppApp的析构函数~CGdiAppApp():
CGdiAppApp::~CGdiAppApp()//
{
GdiplusShutdown(m_pGdiToken);//
}
6
参考资料:
http://www.qylz.net/code/20110430/2854.html
http://topic.csdn.net/u/20091109/12/6f40ed2b-8e3c-465c-a49f-3f184d95fedd.html
http://d.download.csdn.net/down/2751392/hastings
#define iterator _iterator #ifdef _DEBUG namespace Gdiplus { namespace DllExports { #include <GdiplusMem.h> }; #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 nSize, LPCSTR lpszFileName, int nLine) { return DllExports::GdipAlloc(nSize); } void operator delete(void* p, LPCSTR lpszFileName, int nLine) { DllExports::GdipFree(p); } }; #endif // #ifndef _GDIPLUSBASE_H } #endif // #ifdef _DEBUG #include <gdiplus.h> #undef iterator //// Ensure that Gdiplus.lib is linked. #pragma comment(lib, "gdiplus.lib")
在stdafx.h包含GdiNew.h
#include "GdiNew.h" using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib")
第二步: 在类中添加成员变量
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
第三步: 在类的初始化Init()中添加
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
第四步: 在销毁函数ExitInstance()或类析构函数中添加
GdiplusShutdown(gdiplusToken);
................................................................................................
................................................................................................
可能出现的一些问题:
在第一步: 在stdafx.h头文件中 加入gdi+头文件时
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
注意: 这样有时可能会跳出106个错误
类似 error C2146: 语法错误 : 缺少“;”(在标识符“GraphicsState”的前面)
error C2065: “META_SETBKCOLOR”: 未声明的标识符
原因:gdi+ 头文件中的一些宏定义未声明
解决方法: 在 #inclue<gdiplus.h>前 加入新的头文件 #include<afxdtctl.h> 即用如下代码:
#include <afxdtctl.h>
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
以下为网上资料 : 在SDI单文档程序中,如何使用GDI+
1
在stdafx.h内添加如下代码: #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif #include "GdiPlus.h" using namespace Gdiplus; #pragma comment(lib,"gdiplus.lib")
2
在GdiApp.h里的CGdiAppApp中加入两个成员: GdiplusStartupInput m_gdiplusStartupInput;// ULONG_PTR m_pGdiToken;//
3
在GdiApp.cpp中的CGdiAppApp构造函数CGdiAppApp()添加如下代码: GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL);//
4
在GdiApp.h里给CGdiAppApp添加一个析构函数~CGdiAppApp();
5
在GdiApp.cpp中添加CGdiAppApp的析构函数~CGdiAppApp():
CGdiAppApp::~CGdiAppApp()//
{
GdiplusShutdown(m_pGdiToken);//
}
6
在GdiAppView.h的CGdiAppView中添加成员变量: Image* m_pImage; // 原文是BITMAP 不过我觉得还是使用Image方便些 并在GdiAppView.cpp中的GdiAppView构造函数和析构函数中添加如下代码: CGdiAppView::CGdiAppView():m_pImage(0)// { // TODO: add construction code here } CGdiAppView::~CGdiAppView() { delete m_pImage;// m_pImage=0;// }
参考资料:
http://www.qylz.net/code/20110430/2854.html
http://topic.csdn.net/u/20091109/12/6f40ed2b-8e3c-465c-a49f-3f184d95fedd.html
http://d.download.csdn.net/down/2751392/hastings
相关文章推荐
- 初始化GDI+环境
- 初始化 GDI+ 环境(转)
- GDI+环境初始化
- GDI+学习笔记之GDI+环境初始化
- GDI+初始化环境
- GDI+学习笔记之GDI+环境初始化
- VC中初始化GDI+绘图环境
- GDI+学习笔记之GDI+环境初始化
- 初始化GDI+环境
- 初始化 GDI+ 环境
- GDI+学习笔记之GDI+环境初始化
- C++ GDI+环境的初始化
- GDI+学习笔记之GDI+环境初始化
- python-flask项目填坑进行时—建立初始化迁移环境
- 学习altas笔记[客户端JS和Altas环境初始化关系和DataTable返回数据的客户端处理]
- 记录OGG生产环境重新初始化
- vs2005 sp1 补丁后,不能初始化
- Graphics.h画线函数和初始化绘制环境
- Flash CS3动作面板打开出错[Java运行时环境初始化时出现错误
- 基于Armv4I WINCE 5.0 应用程序开发环境搭建(C# VS2005或者VS2008)