1. 载入GDI+
链接器\输入\附加依赖项 中加入lib gdiplus.lib2.GDI+初始化
设置成员变量(包括了双缓冲)
GdiplusStartupInput m_Gdistart;
ULONG_PTR m_GdiplusToken;
CDC m_cDCBuffer; //缓冲CDC
CBitmap m_bmBuffer; //缓冲位图
启动GDI+
GdiplusStartup(&m_GdiplusToken,& m_Gdistart,NULL);
设置内存缓冲
CRect rcClient;
GetClientRect(rcClient);
//画图前的缓冲准备工作
//CPaintDC dc(this); // device context for painting
CDC* pCDC = this->GetDC();
m_cDCBuffer.CreateCompatibleDC(NULL);
m_bmBuffer.CreateCompatibleBitmap(pCDC, rcClient.Width() + rcClient.left, rcClient.Height() + rcClient.top);
m_cDCBuffer.SelectObject(&m_bmBuffer);
m_cDCBuffer.FillSolidRect(rcClient, RGB(255,255,255/*240, 240, 240*/));
//在内存绘图结束后
pCDC->BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(),
&m_cDCBuffer, rcClient.left, rcClient.top, SRCCOPY);
m_cDCBuffer.DeleteDC();
m_bmBuffer.DeleteObject();
3. 将GDI+关联到内存缓冲
HDC hdc = m_cDCBuffer.GetSafeHdc();
Graphics graphics(hdc);
4.启动绘图,绘图,结束绘图
PAINTSTRUCT ps;
BeginPaint(&ps);
Pen pen(Color(255, 0, 0, 0), 1);
Pen pen1(Color(255, 0, 0, 0), 1);
Point myPointArray[10] =
{Point(0, 0), Point(500, 200), Point(800, 600), Point(1000, 350)};
graphics.DrawCurve(&pen, myPointArray, 4, 0.2f);
EndPaint(&ps);
5. 释放GDI+
GdiplusShutdown(m_GdiplusToken);