注:如果包含<gdiplus.h> 后出现编译错误,那么看看stdafx.h中有没有定义WIN32_LEAN_AND_MEAN,有的话注释掉就OK
【1】添加文件头与库
#include <gdiplus.h> using namespace Gdiplus; #pragma comment(lib, "GdiPlus.lib")
ULONG_PTR m_gdiplusToken;
Gdiplus::GdiplusStartupInput StartupInput; GdiplusStartup(&m_gdiplusToken,&StartupInput,NULL);
Gdiplus::GdiplusShutdown(m_gdiplusToken);
Gdiplus::Graphics graphics(hDC); Gdiplus::SolidBrush solidBrush(Gdiplus::Color::Red); Gdiplus::FontFamily fontFamily(L"宋体"); Gdiplus::Font font(&fontFamily, 16, FontStyleRegular, UnitPoint); graphics.DrawString(L"GDI+程序示意", -1, &font, Gdiplus::PointF(0, 0), &solidBrush); graphics.ReleaseHDC(hDC);
class GdiPlusIniter{ public: GdiPlusIniter(){ Gdiplus::GdiplusStartupInput StartupInput; GdiplusStartup(&m_gdiplusToken,&StartupInput,NULL); } ~GdiPlusIniter(){ Gdiplus::GdiplusShutdown(m_gdiplusToken); } private: ULONG_PTR m_gdiplusToken; };
参考文章:
http://www.cnblogs.com/hdtianfu/archive/2013/05/10/3071479.html