以VS2008 MDI为例,
step1.在文件stdafx.h中加入如下代码
#include <GdiPlus.h>
#pragma comment(lib, "gdiplus.lib")
using namespace Gdiplus;
#ifndef ULONG_PTR
#define ULONG_PRT unsigned long*
#endif
step2. 定义全局变量,如下所示.
// The one and only CPhotoMeterApp object
CPhotoMeterApp theApp;
//初始化gdiplus的环境
ULONG_PTR gdiplusToken;
//......
step3.在InitInstance()函数初始化GDI+
// Initialize GDI+.
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
step4.在ExitInstance()函数中销毁GDI+
//shutdown GDI+
Gdiplus::GdiplusShutdown(gdiplusToken);
step5.在void CAboutDlg::OnPaint()举个GDI+绘制的例子
void CAboutDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
Graphics graphics(dc.GetSafeHdc()); //Graphics graphics(dc.m_hDC);也可以
CRect rect;
GetDlgItem(IDC_STATIC_FRAME)->GetWindowRect(&rect); //IDC_STATIC_FRAME是个picture控件,visible=false
ScreenToClient(&rect);
//Brush
Gdiplus::LinearGradientBrush lingrbrush(Gdiplus::Rect(rect.left, rect.top, rect.Width(), rect.Height()), // 绘制区域
Color(250, 248,242,240), // 第一种颜色
Color(250, 255,255,255), // 第二种颜色
(Gdiplus::REAL)(270)); // 渐变色的角度
graphics.FillRectangle(&lingrbrush, Gdiplus::Rect(rect.left,rect.top,rect.Width(),rect.Height() ) );
Gdiplus::Pen pen(Color(255,145,155,156));
Gdiplus::Pen penshade(Color(100,145,155,156));
graphics.DrawRectangle(&pen,Gdiplus::Rect(rect.left,rect.top,rect.Width(),rect.Height()));
graphics.DrawRectangle(&penshade,Gdiplus::Rect(rect.left,rect.top,rect.Width()+1,rect.Height()+1));
// 不为绘图消息调用 CDialog::OnPaint()
}
step6.贴图效果
step7.列外,CSDN的博客做的真TMD差劲.不兼容Chrome,写文章界面一点都不有好,还IT社区,一帮吃shi的,,,