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

Cra*_*ann 5 c++ mfc gdi+

我无法在我的 VS2012 MFC C++ 项目(在 Win7 上)中使用 GDI+ 1.1 类。类 Image、Bitmap、Graphics 工作得很好,但是当我尝试声明 Blur 类(或其他 v1.1 类)的对象时,我得到了一个error C2065: ‘Blur’: undeclared identifier. 我试图这样定义GDIPVER(在 stdafx.h 中)

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

但它不起作用。

如何打开 GDI+ 1.1 而不是 1.0?

jsc*_*edl 5

我在一个项目上与类似的问题斗争了一段时间。对我来说,我的预编译头文件是这样的:

#define GDIPVER     0x0110  // Use more advanced GDI+ features
Run Code Online (Sandbox Code Playgroud)

但预编译的头文件不 #include "gdiplus.h"。这仅发生在实际进行 GDI+ 调用的 .cpp 文件中。我为具有 GDI+ 对象指针作为成员的标头转发声明 GDI+ 类。正如 Hans 和其他评论指出的那样,在设置 GDIPVER 之前可能还有另一个头文件,包括 gdiplus.h。要找出它包含的位置,请尝试转到项目的 C/C++ > 命令行设置并添加 /showIncludes,然后执行完整构建并查看 gdiplus.h 的构建日志,并回溯到包含它的第一个标头。

一旦你清除了这个障碍,我还发现我的应用程序实际上不会使用 1.1 功能,除非清单也被更新。所以我的 .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
Run Code Online (Sandbox Code Playgroud)