摘自:http://www.cnblogs.com/CSGrandeur/p/3156843.html (已实验,可行)

1、配置GDI+

VS2010自带GDI+,直接使用。

(1)首先要添加头文件和库

#pragma comment( lib, "gdiplus.lib" )
#include "gdiplus.h"
using namespace Gdiplus;

建议添加到stdafx.h里

(2)然后添加全局变量

static ULONG_PTR m_gdiplusToken;

该成员变量用来保存GDI+被初始化后在应用程序中的GDI+标识。

(3)在OnInitDialog()之类的初始化函数中,添加:

Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

(4)结束后卸载GDI+:

可以手动重载析构函数然后加上这句:

Gdiplus::GdiplusShutdown(m_gdiplusToken);

头文件中添加:virtual ~CConFontChDlg();

一定要加上virtual关键字,否则在主窗口销毁时,将不会调用我们自己创建的析构函数。

源文件中,在构造函数下面添加:

CConFontChDlg::~CConFontChDlg()

{

...

}

这样就可以在析构函数中,添加我们想添加的代码了。

配置方法很多博客都有说,也不知道源头在哪,恕我不标注来源了。

摘自:http://bbs.csdn.net/topics/330171017

   http://www.cnblogs.com/it20120227/archive/2011/12/31/2370903.html

首先,VS2010中已经有GDI+SDK包的,不需要额外下载
1:在stdafx.h文件中加入下面3行代码,添加相应的头文件和库
  #pragma comment( lib, "gdiplus.lib" )
  #include "gdiplus.h"
  using namespace Gdiplus;
2:定义一个全局变量 ULONG_PTR m_gdiplusToken;
其中,ULONG_PTR是一个DWORD数据类型,该成员变量用来保存GDI+被初始化后在应用程序中的GDI+标识,以便能在应用程序退出后,引用该标识来调用Gdiplus:: GdiplusShutdown来关闭GDI+。
3:使用GDI+函数前,先,最好放在OnInitDialog()中
 Gdiplus::GdiplusStartupInput gdiplusStartupInput;
  Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

或者

3.在C****App的InitInstance()中加入:
//初始化GDI+
GdiplusStartupInput gsi;
GdiplusStartup(&m_gdiplusToken,&gsi,NULL);
4.重载ExitInitInstance()函数
  Gdiplus::GdiplusShutdown(m_gdiplusToken);
这就是基本的配置了

摘自:http://blog.sina.com.cn/s/blog_4f91596001008otf.html

在MFC里使用GDI+

(2008-03-12 11:31:20)

 

1. 在"stdafx.h"里加入以下:
#include <gdiplus.h>
using namespace
Gdiplus;
#pragma comment(lib, "gdiplus.lib")
 
2. 为CWinApp的派生类增加两个成员:
ULONG_PTR
m_gdiplusToken;
GdiplusStartupInput m_gdiplusStartupInput;
 
3. 在该派生类的InitInstance()函数中加入
GdiplusStartup(&m_gdiplusToken,
&m_gdiplusStartupInput, NULL);
 
4. 在该派生类的ExitInstance()函数中加入
GdiplusShutdown(m_gdiplusToken);
 
5. 到此,基本上已经可以用了,例如:
Graphics g(this->GetSafeHwnd(),TRUE);
Pen
myPen(Color::Red,50);
myPen.SetWidth(20);
g.DrawLine(&myPen,50, 50,
145, 365);
 
6. 但是,假如你用以下代码却不能编译通过:
Graphics
g(this->GetSafeHwnd(),TRUE);
Pen* myPen = new
Pen(Color::Red,50);
g.DrawLine(myPen,50, 50, 145, 365);
提示
error C2660:
“Gdiplus::GdiplusBase::operator new” : 函数不接受 3 个参数
的错误。
 
7. 要解决此问题,需参考微软的文章,全文如下:

PRB: Microsoft Foundation
Classes DEBUG_NEW Does Not Work with GDI+

Article ID : 317799
Last Review : February 12,
2007
Revision : 2.1

This article was previously published under Q317799

SYMPTOMS
When you build a
debug version of a Microsoft Foundation Classes (MFC) application that uses
GDI+, you may receive an error message that resembles the following:
error C2660: 'Gdiplus::GdiplusBase::operator new' : function does
not take 3 parameters

CAUSE
In debug builds, MFC
defines a preprocessor macro that expands the new operator to an overloaded new
operator that takes two extra parameters. The extra parameters are the source
file name and code line number. MFC can use this information to report memory
leaks to the programmer when in debug mode. This works for MFC classes because
MFC provides overloads for new that accept the extra parameters.

However, because this expansion is done by the preprocessor, it
affects all usage of the new operator. If any non-MFC classes are used in the
project, their new operator is also expanded, even if no suitable overload of
new is available in that class. This is what happens in GDI+, and as a result,
you receive a compile-time error message.

WORKAROUND
To work around
this problem, choose one of the following methods:

" Turn off the preprocessor expansion by commenting
out the following lines of code in the source file:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif

NOTE: This method has the disadvantage of
not using features in MFC that help you track memory allocations and
leaks.

" Provide GDI+ with overloads for new and delete operators by
writing some code that accepts and discards the additional parameters. You can
paste the following code, which demonstrates this approach, into a new header
file and include the new header file instead of the Gdiplus.h file.

//// Ensure that GdiPlus header files work properly with
MFC DEBUG_NEW and STL header files.

#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")

 
 

【vs2013】如何在VS的MFC中配置使用GDI+?的更多相关文章

  1. 如何在Maven和Gradle中配置使用Groovy 2.4与Spock 1.0

    如何在Maven和Gradle中配置使用Groovy 2.4与Spock 1.0 原文 https://dzone.com/articles/spock-10-groovy-24 翻译 hxfiref ...

  2. 如何在VS和CB中配置MySQL环境

    这里,由于我的MySQL安装在D盘 MY SQL\MySQL Server 5.6该路径下,所以后面的路径均以D:\MY SQL\MySQL Server 5.6开头 在VS中配置MySQL环境 包含 ...

  3. 如何在web.config文件中配置Session变量的生命周期

    实例说明:在网上购物商城中,为了维护在线购物环境,一般只有注册会员才可以购买商品.实现购物功能时,先通过Session变量记录会员的登录名,然后在购买商品页面通过判断会员是否登录确定其能否购买商品. ...

  4. 如何在WTL和MFC中使用duilib及如何静态使用duilib库!(初级讲解 附带一个Demo)

    关于duilib的历史,我也就不多说了,能看到这篇文章的人都是有一定了解才能找到这个的. 我直接说下对这个库的基本使用吧. 我个人对一些好技术都是比较感兴趣的. 因为个人原因 喜欢接触一个好技术. 所 ...

  5. 如何在Windows Server 2003中配置FTP站点服务

    前面写过一篇文章<怎样给你的网站注册一个好域名?> ,讲到“玉米”,笔者有很深的情节,也希望与大家交流“米事”,可以站内私信我或者直接回复文章. 有了好域名只是做网站的开始.我们还要买主机 ...

  6. 如何在IIS7/7.5上配置IISADMPWD

    问题 很多IIS用户还记得在早期的IIS版本上有一个web应用, IISADMPWD. 该应用是与IIS5 和IIS6一起发布的. 主要用于为域用户提供修改密码的功能, 同时也可以修改本机用户的密码. ...

  7. How To Configure VMware fencing using fence_vmware_soap in RHEL High Availability Add On(RHEL Pacemaker中配置STONITH)

    本文主要简单介绍一下如何在RHEL 7 Pacemaker中配置一个fence_vmware_soap类型的STONITH设备(仅供测试学习). STONITH是Shoot-The-Other-Nod ...

  8. How To Configure VMware fencing using fence_vmware_soap in RHEL High Availability Add On——RHEL Pacemaker中配置STONITH

    本文主要简单介绍一下如何在RHEL 7 Pacemaker中配置一个fence_vmware_soap类型的STONITH设备(仅供测试学习). STONITH是Shoot-The-Other-Nod ...

  9. vs2013如何在C++中调用Lua(二)

    Lua学习笔记 vs2013如何在C++中调用Lua (此为转载教程) 本人试过完全可行 一.准备工作 1.下载Lua源码,地址:http://www.lua.org/download.html(我用 ...

随机推荐

  1. CodeForces - 987E Petr and Permutations (思维+逆序对)

    题意:初始有一个序列[1,2,...N],一次操作可以将任意两个位置的值互换,Petr做3*n次操作:Alxe做7*n+1次操作.给出最后生成的新序列,问是由谁操作得到的. 分析:一个序列的状态可以归 ...

  2. Mac 一键显示所有隐藏文件 不要那么六好吧

    系统应简洁而有效,对一般用户来说这一点尤为重要.不必要让普通用户知道的信息往往会给他们造成困扰,因而,隐藏掉他们便是个不错的选择,既可以保证系统平稳流畅运行,也可以为用户提供友好界面. 对于开发者而言 ...

  3. java 工厂模式的作用,为什么要用工厂模式以及示例演示

    1 工厂模式的作用,为什么要用工厂模式? 工厂模式是为了解耦:把对象的创建和使用的过程分开.就是Class A 想调用Class B,那么只是调用B的方法,而至于B的实例化,就交给工厂类. 工厂模式可 ...

  4. NIO复习03

    SocketChannel: 1. Java NIO中的SocketChannel是一个连接到TCP网络套接字的通道.可以通过以下2种方式创建SocketChannel: 打开一个SocketChan ...

  5. CentOS7种搭建FTP服务器

    1.安装vsftpd #首先要查看你是否安装vsftp [root@localhost /]# rpm -q vsftpd vsftpd-3.0.2-10.el7.x86_64             ...

  6. hadoop16---反射

    框架配置文件中,从字符串获取类和实例,调他的方法. 通过反射的方式可以获取class对象中的属性.方法.构造函数等,一下是实例: package cn.itcast_04_reflect; impor ...

  7. [转]毕设- 深入HBase架构解析(二)

    深入HBase架构解析(二) 前言 这是<深入HBase架构解析(一)>的续,不多废话,继续.... HBase读的实现 通过前文的描述,我们知道在HBase写时,相同Cell(RowKe ...

  8. JavaScript传递的是引用的副本

    看例子 var test1 = function (args) { args.name = "lcc2"; args = { name: "lcc3" }; } ...

  9. html 5中的新特性之强化表单元素及属性

    之前我们判断用户提交的是否是Email 的时候,往往使用js 进行判断,但在html5中可以有新的方式进行判断而且更简单 <!DOCTYPE html> <html lang=&qu ...

  10. 深入解析Koa之核心原理

    这篇文章主要介绍了玩转Koa之核心原理分析,本文从封装创建应用程序函数.扩展res和req.中间件实现原理.异常处理的等这几个方面来介绍,写的十分的全面细致,具有一定的参考价值,对此有需要的朋友可以参 ...