1、在你的app类头文件中假如以下代码(红字显示)
#if !defined(AFX_WALKLTDEMO_H__826A807C_C01D_4FF0_9248_A6BD0369F3A8__INCLUDED_) #define AFX_WALKLTDEMO_H__826A807C_C01D_4FF0_9248_A6BD0369F3A8__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH #endif #include "resource.h" // main symbols //加入gdi+支持 #ifndef ULONG_PTR #define ULONG_PTR unsigned long* #endif #include "gdiplus.h" using namespace Gdiplus; #pragma comment(lib, "gdiplus.lib") ///////////////////////////////////////////////////////////////////////////// // CWalkLtDemoApp: // See WalkLtDemo.cpp for the implementation of this class // class CWalkLtDemoApp : public CWinApp { public: CWalkLtDemoApp();
2、在app类的源文件里加入以下代码
///////////////////////////////////////////////////////////////////////////// // The one and only CWalkLtDemoApp object CWalkLtDemoApp theApp; // add for gdi+ --------------- GdiplusStartupInput g_gdiplusStartupInput; ULONG_PTR g_gdiplusToken; //----------------------------------- ///////////////////////////////////////////////////////////////////////////// // CWalkLtDemoApp initialization BOOL CWalkLtDemoApp::InitInstance() { // add for Gdi+ --------------- GdiplusStartup(&g_gdiplusToken,&g_gdiplusStartupInput,NULL); //----------------------------------- // 设置 GDIPLUS 样例图片所在目录 ------------ // ---- 假设为 本执行程序所在目录下的 gidplus_demo_data TCHAR ModuleDirectory[_MAX_PATH]; ::GetModuleFileName(NULL, ModuleDirectory, _MAX_PATH); TCHAR *p=::_tcsrchr(ModuleDirectory, '\\'); if (p) { *p=0; ::_tcscat(ModuleDirectory, "\\gidplus_demo_data"); ::SetCurrentDirectory(ModuleDirectory); } //----------------------------------- AfxEnableControlContainer(); // Standard initialization
3、在你生成的exe所在文件夹下新建一个资源文件夹 gidplus_demo_data,将图像资源放置到这个文件夹下。
否则你在创建图像文件时会不成功。
浙公网安备 33010602011771号