如何在 MFC 项目中打开 GDI+ 1.1 而不是 1.0
How to turn on GDI+ 1.1 instead of 1.0 in MFC project?
我无法在我的VS2012 MFC C++项目(在Win7上)中使用GDI+ 1.1类。类图像,位图,图形工作得很好,但是当我尝试声明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")
但它不起作用。
如何打开GDI+ 1.1而不是1.0?
我在一个项目上与类似的问题斗争了一段时间。对我来说,我的预编译头有这个:
#define GDIPVER 0x0110 // Use more advanced GDI+ features
但是预编译的标头不会 #include"gdiplus.h"。这仅发生在实际进行 GDI+ 调用的.cpp文件中。 我为将 GDI+ 对象指针作为成员的标头转发声明 GDI+ 类。正如Hans和其他评论所指出的,在设置GDIPVER之前,可能还有另一个包含gdiplus.h的标题。要确定它包含的位置,请尝试转到项目的 C/C++> 命令行设置并添加/showInclude,然后执行完整构建并查看 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
FWIW,我做了以下操作来在VS 2019 MFC项目中启用GDI+ 1.1:
- 在包含
pch.h
之前,在pch.cpp
中添加了此行:#define GDIPVER 0x0110
在 - 包含
framework.h
:#include <gdiplus.h>
using namespace Gdiplus;
之后,在pch.h
中添加了这些行 - 使用了 7 年前 @jschroedl (!) 善意提供的代码块的略微修改和更新版本:
// 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
我在启动代码中实例化了一个 Blur
对象,以验证我是否针对 GDI+ 1.1 进行编译并限定其范围,以便在调用 GdiplusShutdown()
之前将其销毁,并且该应用程序在 x86 和 x64 版本中都正确运行和关闭。
通过在包含任何标头之前将 GDIPVER 定义为0x0110,您可以访问 GDIPlus 1.1 功能。例如,在框架中,
define GDIPVER 0x0110
#include <windows.h>
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
- C++ MFC Libraries in Travis CI
- 从 bmp 文件数据创建 MFC CBitmap
- 如何在 MFC 中显示文件的所有行
- 目录删除 MFC 的问题
- MFC:如何设置CEdit框的焦点?
- MFC 中的抗锯齿
- 双击更改 mfc 中列表控件中的行的颜色
- C++MFC编辑框处理双击
- C++ MFC CObject 派生类摘要?
- 如何在 MFC 对话框中使用 OnDraw
- 在 1 个服务器 n 客户端套接字 C++ MFC 应用程序中更新数据的客户端
- 如何使用GDI 显示具有25%不透明度的PNG图像?(MFC)
- 如何在MFC对话框上绘制/创建GDI
- GDI 在 MFC 中修改字体
- HDC 未定义 [GDI+,MFC 标准应用程序]
- 如何在 MFC 项目中打开 GDI+ 1.1 而不是 1.0
- 如何在 GDI 绘制的 MFC 的 CScrollView 中实现缩放
- 使用MFC的跨进程GDI绘图
- 记录屏幕时不出现的奇怪的 MFC/GDI 行为(空白图像)
- 如何在C++/MFC / GDI中创建非常大的位图