Step1.在stdafx.h中加入GDI+的Header file
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
Step2.在CWinApp中加入成員變數
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
在CWinApp::InitInstance()中初始化GDI+資源
GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
Step3.至此,你的程式即可開始使用GDI+囉~
Step4.程式結束前,需釋放GDI+資源,請在CWinApp::ExitInstance()中加入:
GdiplusShutdown(gdiplusToken);
以小弟需求來說--->漸層<---以下程式碼請參考:
/*****MyClass.h*****/
class CMyClass:public CWnd
{
DECLARE_DYNAMIC(CMyClass)
public:
CMyClass();
virtual ~CMyClass();
protected:
afx_msg void OnPaint();
private:
Gdiplus::PointF m_gdiPoint1,m_gdiPoint2;
Gdiplus::Color m_gdiColor1,m_gdiColor2;
};
/*****MyClass.cpp*****/
CMyClass::CMyClass()
{
vm_gdiPoint1 =PointF(0,0);
vm_gdiPoint2 =PointF(0,18);
vm_gdiColor1 =Color(255,255,255);
vm_gdiColor2 =Color(0,0,0);
}
void CMyClass::OnPaint()
{
CPaintDC dc(this);
CRect rcBar;
GetClientRect(&rcBar);
//GDI+
Gdiplus::LinearGradientBrush gdiBrush(m_gdiPoint1,m_gdiPoint2,m_gdiColor1,m_gdiColor2);
Gdiplus::RectF gdiRc((Gdiplus::REAL)rcBar.left,(Gdiplus::REAL)rcBar.top, (Gdiplus::REAL)rcBar.Width(),(Gdiplus::REAL)rcBar.Height());
Graphics grThis(dc.m_hDC);
grThis.FillRectangle( &gdiBrush, gdiRc);
}
ref:CodeProject_GDI+
ref:MSDN_GDI+