简体   繁体   English

如何在 MFC 项目中打开 GDI+ 1.1 而不是 1.0?

[英]How to turn on GDI+ 1.1 instead of 1.0 in MFC project?

I unable to use GDI+ 1.1 classes in my VS2012 MFC C++ project (on Win7).我无法在我的 VS2012 MFC C++ 项目(在 Win7 上)中使用 GDI+ 1.1 类。 Classes Image, Bitmap, Graphics works just fine but when I try to declare an object of Blur class (or other v1.1 classes) I am getting an error C2065: 'Blur': undeclared identifier . Classes Image, Bitmap, Graphics 工作得很好,但是当我尝试声明 object 的 Blur class(或其他 v1.1 类)时,我收到error C2065: 'Blur': undeclared identifier I tried to define GDIPVER (in stdafx.h) like this我试图像这样定义GDIPVER (在 stdafx.h 中)

#define GDIPVER 0x0110 //also I get the warning C4005: 'GDIPVER' : macro redefinition
#include <gdiplus.h>
#pragma comment (lib,"Gdiplus.lib")

but it does not work.但它不起作用。

How to turn on GDI+ 1.1 instead of 1.0?如何打开 GDI+ 1.1 而不是 1.0?

I fought with a similar issue for a while on one project. 我在一个项目上与一个类似的问题进行了一段时间的斗争。 For me, my precompiled header has this: 对我来说,我的预编译头有这个:

#define GDIPVER     0x0110  // Use more advanced GDI+ features

but the precompiled header does not #include "gdiplus.h". 但预编译头不#include“gdiplus.h”。 That only occurs in the .cpp files which actually make GDI+ calls. 这只发生在实际进行GDI +调用的.cpp文件中。 I forward declare GDI+ classes for the headers which have GDI+ object pointers as members. 我转发为具有GDI +对象指针作为成员的头部声明GDI +类。 As Hans and other comments noted, there's probably another header including gdiplus.h before the GDIPVER is set. 正如汉斯和其他评论所指出的那样,在设置GDIPVER之前,可能还有另一个包括gdiplus.h的标题。 To figure out where it's included try going to the C/C++ > Command Line settings for your project and add /showIncludes then do a full build and look in the build log for gdiplus.h and track back to the first header including it. 要确定它的位置,请尝试转到项目的C / C ++>命令行设置并添加/ showIncludes然后执行完整构建并查看gdiplus.h的构建日志并跟踪回包含它的第一个头。

Once you clear that hurdle, I also discovered my application would not actually use the 1.1 features unless the manifest was also updated. 一旦你清除了这个障碍,我也发现我的应用程序实际上不会使用1.1功能,除非清单也被更新。 So one of my .cpp files has this: 所以我的一个.cpp文件有这个:

// Update Manifest
// cf: http://blogs.msdn.com/b/oldnewthing/archive/2007/05/31/2995284.aspx
//
// We use features from GDI+ v1.1 which is new as of Windows Vista. There is no redistributable for Windows XP.
// This adds information to the .exe manifest to force GDI+ 1.1 version of gdiplus.dll to be loaded on Vista
// without this, Vista defaults to loading version 1.0 and our application will fail to launch with missing entry points.
#if 64BIT_BUILD
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

FWIW, I did the following to enable GDI+ 1.1 in a VS 2019 MFC project: FWIW,我执行了以下操作以在 VS 2019 MFC 项目中启用 GDI+ 1.1:

  1. Added this line in pch.cpp before including pch.h :在包含pch.cpp之前pch.h中添加了这一行:
    #define GDIPVER 0x0110
  2. Added these lines in pch.h after including framework.h :在包含framework.h之后pch.h中添加了这些行:
    #include <gdiplus.h>
    using namespace Gdiplus;
  3. Used a slightly modified and updated version of the code block kindly provided by @jschroedl 7 (:) years ago:使用@jschroedl 7 (:) 多年前提供的代码块的略微修改和更新版本:
// Update Manifest
// cf: http://blogs.msdn.com/b/oldnewthing/archive/2007/05/31/2995284.aspx
//
// We use features from GDI+ v1.1 which was new as of Windows Vista. There is no redistributable for Windows XP.
// This adds information to the .exe manifest to force the GDI+ 1.1 version of gdiplus.dll to be loaded.
// Without this, Windows will load the GDI+ 1.0 version of gdiplus.dll and the application will fail to launch with missing entry points.
#ifdef _WIN64
    //#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
    //#pragma comment(linker, "\"/manifestdependency:type='Win32' name='Microsoft.Windows.GdiPlus' version='1.1.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

I instantiated a Blur object in my startup code to verify I was compiling against GDI+ 1.1 and scoping it so it would be destroyed before calling GdiplusShutdown() , and the app ran and shut down correctly in both x86 and x64 builds.我在我的启动代码中实例化了一个Blur object 以验证我是针对 GDI+ 1.1 进行编译并确定它的范围,以便在调用GdiplusShutdown()之前将其销毁,并且该应用程序在 x86 和 x64 构建中都正确运行和关闭。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM