安装三部曲:
Step1:下载 GdiPlus SDK 文件包 VC6 的安装程序并没有包含 GdiPlus 相关的库文件和头文件,所以想在VC6中使用 GdiPlus,你首先得把这些文件下载到本地。微软的说法是 GdiPlus 相关的库文件和头文件已经合入到 .Net Platform SDK 里面,所以开发人员只需要下载安装 SDK 即可。但也有相当一部分开发人员是不想为了 GdiPlus 就安装 SDK 的,于是就有热心之人从 SDK 中把 GdiPlus 相关的这些文件单独抽离了出来,形成了 GdiPlus SDK 文件包。 你可以尝试通过以下链接地址进行下载: 解压之后,请核对一下文件夹中的目录结构: Step2:安装
我采取的做法是: (2)静态库(GdiPlus.lib)文件安装目录:C:/Program Files/Microsoft Visual Studio/VC98/Lib; (3)动态库(GdiPlus.dll)文件安装目录:Copy 到 exe 文件存放目录或者直接使用系统中自带的 GdiPlus.dll; Step3:配置开发环境下的路径
下面用 VC6 来写一个 GdiPlus 的 Demo 工程
Step1:新建一个名为 Demo_GdiPlus 的 MFC AppWizard(exe) 工程
//
{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. typedef unsigned long ULONG_PTR, * PULONG_PTR; #include < gdiplus.h > using namespace Gdiplus; #pragma comment (lib, "GdiPlus.lib") Step3:在 CDemo_GdiPlusApp 中增加成员变量 m_gdiplusToken,并在构造函数中进行初始化
class
CDemo_GdiPlusApp :
public
CWinApp
{ private : ULONG_PTR m_gdiplusToken; // …… …… }; CDemo_GdiPlusApp::CDemo_GdiPlusApp() { // TODO: add construction code here, // Place all significant initialization in InitInstance m_gdiplusToken = NULL; } Step4:添加安装和卸载 GdiPlus 的代码
//
.h 中的声明
virtual BOOL InitInstance(); virtual int ExitInstance(); // .cpp 中的实现 BOOL CDemo_GdiPlusApp::InitInstance() { // 加载 GdiPlus Gdiplus::GdiplusStartupInput gdiplusStartupInput; Gdiplus::GdiplusStartup( & m_gdiplusToken, & gdiplusStartupInput, NULL); // …… …… } int CDemo_GdiPlusApp::ExitInstance() { // TODO: Add your specialized code here and/or call the base class // 卸载 GdiPlus if (m_gdiplusToken) Gdiplus::GdiplusShutdown(m_gdiplusToken); return CWinApp::ExitInstance(); } Step5:找到 CDemo_GdiPlusView::OnDraw() 函数,在里面添加一段 GdiPlus 的绘图代码
void
CDemo_GdiPlusView::OnDraw(CDC
*
pDC)
{ CDemo_GdiPlusDoc * pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here Graphics graphics(pDC -> GetSafeHdc()); // Pen can also be constructed using a brush or another pen. There is a second parameter - a width which defaults to 1.0f Pen blue (Color( 255 , 0 , 0 , 255 )); Pen red (Color( 255 , 255 , 0 , 0 )); int y = 256 ; for ( int x = 0 ; x < 256 ; x += 5 ) { graphics.DrawLine( & blue, 0 , y, x, 0 ); graphics.DrawLine( & red, 256 , x, y, 256 ); y -= 5 ; } }
|
【转】在VC6中使用 GdiPlus
最新推荐文章于 2024-09-29 12:32:31 发布
在 VC6 中使用 GdiPlus
2008-10-24 01:11