建立一个GDI+的程序需要四个步骤:
1、引入头文件 , 使用命名空间
#include <GdiPlus.h>
using namespace Gdiplus;
2、初始化GDI+系统资源
全局变量 ulong_ptr gdi;
bool xxx::InitInstance()
{
InitCommonControls();
// 初始化GDI+系统资源
GdiplusStartupInput gdiInput;
GdiplusStartup(&gdi, &gdiInput,null);
}
3、使用完后释放GDI+资源
void xxx~xxx()
{
// 销毁GDI+资源
GdiplusShutdown(gdi);
}
4、编译是要加入GDIplus.lib库文件
方法1:在cpp文件中 加入 #pragma comment(lib,"XXX.lib")
方法2:步骤1:Tools->options->projects and solutions->VC++ directories分别在包含文件,库文件填加了路径(这些路径只告诉编译器怎么找文件,没有说把那里面的文件加入工程,若不设置,编译报错:无法打开***文件)
步骤2:Project->properties->c/c++->general->additional include directories 添加包含文件 Project->properties->linker->general->additional library directories 告诉计算机查找LIB的附加路径 Project->properties->linker->input->additional additional dependencies添加用到的lib,(若不添加,连接报错:无法解析的外部符号)。
实例:使用GDI+输出文本
void xxx::OnDraw(CDC*)
{
// 建立Graphics对象
Graphics graphics(this->GetDC()->m_hDC);
// 设定文本输出使用的画笔、色彩、字体
Pen pen(Color(255,0,0,255));
SoldBrush brush(Color(255,0,0,255));
FontFamily fontfamily(L"宋体");
Font font(&fontfamily, 24,FontStyleRegular,UnitPixel);
// 在窗口中央输出文本
CRect rect;
this->GetClientRext(&rect);
PointF pointF(rect.right/2, rect.bottom/2);
graphics.DrawString(L"GDI+程序示意", -1, &font, pointF, &brush);
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。