1. 创建MFC应用程序, CMyApp
2. 在stdafx.h文件中加入GDI+支持
//GDI+支持
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")
3. 在CMyApp.h文件中的CMyApp加入
public:
ULONG_PTR m_pGdiplusToken;
public:
virtual int ExitInstance();
4. 在CMyApp.cpp文件中
在CMyTableApp::InitInstance()函数中加入
GdiplusStartupInput gdiplusStartupInput;
GdiplusStartup(&m_pGdiplusToken, &gdiplusStartupInput, NULL);
在CMyTableApp::ExitInstance()函数中加入
GdiplusShutdown(m_pGdiplusToken);
return CWinApp::ExitInstance();
5. 在CMyAppDlg::OnPaint()函数中加入
CPaintDC dc(this); // 用于绘制的设备上下文
Graphics graphics(dc);
Pen pen(Color(255, 0, 0, 255));
graphics.DrawLine(&pen, 0, 0, 200, 100);