下面用 VC6 来写一个 GdiPlus 的 Demo 工程

Step1:新建一个名为 Demo_GdiPlus 的 MFC AppWizard(exe) 工程

操作步骤:
(1)主菜单File->New...,选择 Projects 选项卡;
(2)在工程类型列表中选中 MFC AppWizard(exe);
(3)Project name 填入 Demo_GdiPlus,按 OK 进入下一页;
(4)选择单文档(Single document)类型的程序框架,按 Finish 完成工程创建工作。

Step2:添加头文件声明

在 StdAfx.h 中添加以下代码:

//{{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 的代码
通过 ClassWizard 在 CDemo_GdiPlusApp 中增加成员函数

// .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;
 }  
}

编译运行,Demo 程序完成。留住这个 Demo 程序,今后我们会利用它进行更加深入的 GdiPlus 学习。

在 VC6 中使用 GdiPlus-使用相关推荐

  1. 在 VC6 中使用 GdiPlus-安装

    安装三部曲: Step1:下载 GdiPlus SDK 文件包: 链接地址1:http://www.codeguru.com/code/legacy/gdi/GDIPlus.zip 链接地址2:htt ...

  2. VC6中根据需要显示滚动条

    为什么80%的码农都做不了架构师?>>>    在VC6中,如果在已经搭建好的工程里面添加简单的工具条(不用自己控制步长)的方法: 1.将视图类的基类改为CScrollView.注意 ...

  3. VC6中使用高版本系统API的方法

    有同学在如鹏论坛提问,在VC6中使用GetListBoxInfo这个API函数的时候编译提示: 'GetListBoxInfo' : undeclared identifier 详见:http://s ...

  4. VC6中使用内存DC加载并显示JPG图片的注意事项

    From: http://blog.csdn.net/boythl/article/details/3137446 今天在VC6中显示JPG图片,采用了内存DC缓存的方法刷新,但死活刷不出来,查了一下 ...

  5. vc可以实现对话框里显示html文档内容,也可以显示word内容吗,VC6中使用CHtmlView在对话框控制中显示HTML文档...

    VC6中使用CHtmlView在对话框控制中显示HTML文档 2008-02-23 05:29:58来源:互联网 阅读 () 在Visual Studio 6.0中出现了一个新类CHtmlView,利 ...

  6. 解决 “计算机中丢失gdiplus.dll”

    装了某些精简版Ghost系统的人,可能在打开个别软件时,弹出以下提示: 无法启动此程序,因为计算机中丢失 gdiplus.dll.尝试重新安装该程序以解决问题. 这类问题,网上都是千篇一律的答案.让你 ...

  7. VC6中工具条的新特色 (转)

    VC6中工具条的新特色 (转)[@more@] VC6中工具条的新特色 加入时间:01-1-8 下午 09:10:32 在Visual C++ 版本6中工具条的新特色 作者: Dave Schmitt ...

  8. Windows异常世界历险记(五)——VC6中结构化异常处理机制的反汇编分析(下)

    在本系列的上一篇文章Windows异常世界历险记(四)--VC6中结构化异常处理机制的反汇编分析(中)中,给出了针对VC6的异常处理机制进行逆向后得到的伪码.在本文中,我们仍然以之前写的小程序为例,通 ...

  9. 无法启动此程序因为计算机丢失gdiplus,处理系统提示无法启动此程序,因为计算机中丢失gdiplus.dll的方法...

    在使用计算机的时候经常会出现某某文件丢失的情况,有位用户在使用电脑的时候就有遇到系统提示:"无法启动此程序,因为计算机中丢失gdiplus.dll.尝试重新安装该程序以解决此问题." ...

  10. 计算机中丢失gdiplus.dll 解决方法 适用windows 2000.

    笔者遇到问题如下: 由于需要用到Windows2000运行某些软件,所以在虚拟机里安装了一个Windows2000,msdn 我告诉你 下载后安装ULtraedit32 版本V17 china 站长 ...

最新文章

  1. Nhibernate 三种配置方式
  2. codeforces 15C. Industrial Nim
  3. hoj 13788 Dwarves
  4. .gitignore文件_【第1739期】为Git仓库里的.idea文件夹正名
  5. Spring Boot文档阅读笔记-对Securing a Web Application解析
  6. CentOS 7安装megacli
  7. 手机输入法带拼音声调_这些神奇的拼音输入法,你都知道几个?
  8. Packet Tracer官网下载
  9. 安装vue-cli创建项目的时候 gyp ERR! build error的npm包遇到以下错误
  10. 智能管家项目总结(2)
  11. 【mysql】mysql 中 text,longtext,mediumtext 字段类型的意思, 以及区别
  12. dede 百度主动推送插件
  13. 小程序 wxml里时间戳转日期
  14. Measurement Studio函数ReadMultiSampleAsync
  15. Scala编程——下界介绍与实例分析
  16. 第二章教程16:贪吃蛇
  17. 2023年系统集成项目管理工程师报考条件及时间安排
  18. scratch案例——九九乘法
  19. 【小程序】图片加载时出现拉扯感,抖动感。
  20. Ubuntu20.04 ros安装 摄像头

热门文章

  1. 2019数字化趋势:未来5年政府、零售数字化程度将达80%
  2. 新能源汽车:大变革催生十万亿市场空间
  3. 人机交互与智能的思考
  4. 腾讯「AI In All」的背后,是开放AI技术能力,探索腾讯应用场景
  5. 去年我年薪 30W,今年我一天做 3 顿饭
  6. ​10.24,华为鲲鹏要为程序员发福利!
  7. 你必须知道的指针基础-3.指针的移动及指针的危险
  8. HttpSessionActivationListener接口 学习笔记
  9. j2ee关于响应头的传输猜想
  10. linux 中mmap的用法