#include
#pragma comment(lib, "GdiPlus.lib")
using namespace Gdiplus;
在应用程序类添加一个保护权限的数据成员:
然后在对话框类的OnInitDialog加上下面初始化代码:
上面代码的作用是初始化GDI+资源。
在应用程序类的OnFinalRelease加上下面代码:
上面代码的作用是销毁GDI+资源。
void CGDIDlg::OnPaint()
{
if (IsIconic())
{
.../*省略*/
}
else
{
CPaintDC dc(this); // 用于绘制的设备上下文
Graphics graphics(dc.GetSafeHdc());
int offsetX = 100;
int offsetY = 50;
Point points[5] = {
Point(offsetX+50,offsetY),
Point(offsetX + 100,offsetY + 50),
Point(offsetX + 50,offsetY+100),
Point(offsetX ,offsetY + 50),
Point(offsetX+50,offsetY)
};
Pen pen1(Color(0, 0, 255), 2);
Pen pen2(Color(255, 0, 0), 2);
graphics.DrawCurve(&pen1, points, 5);
graphics.DrawLine(&pen1, 0, 0, 200, 100);
/*设置平滑绘图*/
graphics.SetSmoothingMode(SmoothingModeHighQuality);
/*建立矩阵*/
Matrix matrix(1.0f,0.0f,0.0f,1.0f,0.0f,0.0f);
matrix.Translate(50.f,150.0f,MatrixOrderAppend);
graphics.SetTransform(&matrix);
graphics.DrawCurve(&pen2, points, 5);
graphics.DrawLine(&pen2, 0, 0, 200, 100);
CDialogEx::OnPaint();
}
}