资源描述
GdiPlus.h等头文件, GdiPlus.lib及GdiPlus.dll的下载地址:
配置方法:
将gdiplus.h, gdiplus.lib分别拷贝至VC相应的include及lib目录下。这两个目录可通过VC6的Tools->Options->Directories标签页中,在Show directories for下拉列表框中分别选择Include files及Library files查询到。如Include,一般包括3个路径:VC98\INCLUDE, VC98\MFC\INCLUDE及VC98\ATL\INCLUDE,分别对应非MFC应用,MFC应用及ATL应用所用的不同路径。
然后在StdAfx.h中加入如下的语句:
#define ULONG_PTR ULONG
#include <afxdtctl.h> //此处必须添加,否则出错
#include <gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "gdiplus.lib")
GdiPlusInit.h中使用了ULONG_PTR的数据类型,但此类型在VC6中没有定义。因此必须在#include语句之前先进行定义。#pragma comment(lib, "gdiplus.lib")指示在连接时在应用所在目录或系统LIB目录下查找gdiplus.lib。
Build(F7)之后将gdiplus.dll拷贝到生成的执行文件所在的文件夹(\Debug或者\Release)
使用GDI Plus类库:
要使用GDI Plus类库,你必须首先初始化类库。初始化是一个调用两个参数的函数,这两个参数是必须在整个GDIPlus会话中都存在的变量。在使用完GDIPlus之后,必须调用一个函数来关闭会话。
如果你使用MFC,一个好的方法是在你的CWinApp派生的类中(比如CYourProjectApp,自己找不到的话就在中查找)添加变量:
private:
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;
然后在app的InitInstance函数中的开始添加一行代码:
GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL); //gdi+ init
然后重载ExitInstance函数(一般都没有这个函数),在其中添加二行代码:
GdiplusShutdown(m_pGdiToken); //gdi+ end session
return CWinApp::ExitInstance();
详细说明:
//***************************************************************
class CGDIplus_TESTApp : public CWinApp
{
public:
CGDIplus_TESTApp();
private:
GdiplusStartupInput m_gdiplusStartupInput;
ULONG_PTR m_pGdiToken;
添加的变量
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGDIplus_TESTApp)
public:
virtual BOOL InitInstance();
virtual BOOL ExitInstance();
重载的ExitInstance函数声明
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CGDIplus_TESTApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//***************************************************************************************
//***************************************************************************************
BOOL CGDIplus_TESTApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
GdiplusStartup(&m_pGdiToken,&m_gdiplusStartupInput,NULL); //gdi+ init
添加的初始化代码
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
//***************************************************************************************
//***************************************************************************************
BOOL CGDIplus_TESTApp::ExitInstance()
添加在BOOL CGDIplus_TESTApp::InitInstance()函数体后面
{
GdiplusShutdown(m_pGdiToken); //gdi+ end session
return CWinApp::ExitInstance();
}
//***************************************************************************************
这些操作之后你就可以在你的程序中使用类库的功能了。
可以使用了么?不可以。我们新建一个单文档的工程,按上面的步骤做完,然后在View类的OnDraw()函数里添加如下代码:
Graphics graphics(pDC->m_hDC);
Pen pen(Color(255, 0, 255));
graphics.DrawLine(&pen, 0, 0, 200, 100);
展开阅读全文