VS2010,新建MFC项目,在头文件stdafx.h中添加:

 #include <gdiplus.h>
using namespace Gdiplus;
#pragma comment (lib,"Gdiplus.lib")

定义类的变量 ULONG_PTR   gdiplusToken;

在BOOL CGDALDesktopApp::InitInstance()中添加:

 GdiplusStartupInput gdiplusStartupInput;
2 GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

在ExitInstance()中添加:

 int CGDALDesktopApp::ExitInstance()
{
//TODO: 处理可能已添加的附加资源
AfxOleTerm(FALSE);
GdiplusShutdown(gdiplusToken);
return CWinAppEx::ExitInstance();
}

添加绘制的代码:

 void CGDALDesktopView::OnDraw(CDC* pDC)
{
CGDALDesktopDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return; //Graphics graphics(*pDC);
Graphics g( pDC->GetSafeHdc() );
//建立画笔
Pen pen_black(Color::Black);
Pen pen_white(Color::White);
//使用画笔绘制图形
pen_black.SetWidth(); //设置画笔宽度
pen_black.SetStartCap(LineCapRoundAnchor); //设置开始笔帽
pen_black.SetEndCap(LineCapArrowAnchor); //设置结束笔帽
g.DrawLine(&pen_black, , , , );
Rect rect1(,, , );
Rect rect2( + , , , );
Rect rect3( + *, , , );
Rect rect4( + *, , , );
g.DrawRectangle(&pen_black, rect1);
g.DrawRectangle(&pen_black, rect2);
g.DrawRectangle(&pen_black, rect3);
g.DrawRectangle(&pen_black, rect4);
//建立画刷
//实色画刷
SolidBrush brush_black(Color::Black);
SolidBrush brush_white(Color::White);
SolidBrush brush_blue(Color::Blue);
g.FillRectangle(&brush_blue, rect1);
//网格画刷
HatchBrush brush_hatch( HatchStyleDiagonalBrick, Color(, , , ), Color(, , , ));
g.FillRectangle(&brush_hatch, rect2);
//贴图画刷
Image image(L"res\\qq.gif");
TextureBrush brush_texture(&image);
g.FillRectangle(&brush_texture, rect3);
//渐变画刷(线形渐变)
LinearGradientBrush brush_gradient_line( Point(, ), Point(, ),Color(, , , ), Color(, , , ));
g.FillRectangle(&brush_gradient_line, rect4);
//渐变画刷(路径渐变)
//PathGradientBrush......................
//贴图画笔
Pen pen_texture(&brush_texture, );
g.DrawEllipse(&pen_texture, , , ,);
//启动抗锯齿功能
pen_black.SetWidth();
g.SetSmoothingMode(SmoothingModeAntiAlias);
g.DrawLine(&pen_black, , , , );
//绘制图像
// 不进行缩放
g.DrawImage(&image, ,);
// 使用低质量的插补算法
g.SetInterpolationMode(InterpolationModeNearestNeighbor);
g.DrawImage( &image, Rect(,, , ));
// 使用中等质量的插补算法
g.SetInterpolationMode(InterpolationModeHighQualityBilinear);
g.DrawImage( &image, Rect(,, , ));
// 使用高质量的插补算法
g.SetInterpolationMode(InterpolationModeHighQualityBicubic);
g.DrawImage( &image, Rect(,, , ));
//路径
GraphicsPath path1;
path1.AddLine(, , ,);
path1.AddArc(, , , , , -);
g.DrawPath(&pen_black, &path1);
g.FillPath(&brush_black, &path1);
//区域
GraphicsPath pathOuter;
pathOuter.AddRectangle(Rect(, , ,));
GraphicsPath pathInner;
pathInner.AddEllipse(Rect(, , ,));
Region rgn(&pathOuter);
rgn.Exclude(&pathInner);
g.FillRegion(&brush_blue, &rgn);
// TODO: 在此处为本机数据添加绘制代码
}

MFC和GDI+一起使用的更多相关文章

  1. MFC 用gdi绘制填充多边形区域

    MFC 用gdi绘制填充多边形区域 这里的代码是实现一个三角形的绘制,并用刷子填充颜色 在OnPaint()函数里面 运用的是给定的三角形的三个点,很多个点可以绘制多边形 CBrush br(RGB( ...

  2. mfc配置GDI+有106个错误

    mfc配置GDI+有106个错误,处理如下,参考http://bbs.csdn.net/topics/380054079 一开始#include...放在stdafx.h里有错误,后来上面修改好了,放 ...

  3. VS2010 MFC 使用GDI+给图片添加汉字

    1.配置GDI+ VS2010自带GDI+,直接使用. (1)首先要添加头文件和库 #pragma comment( lib, "gdiplus.lib" ) #include & ...

  4. MFC用GDI+动感歌词的制作

    源代码:http://download.csdn.net/detail/nuptboyzhb/4219669 源代码: 1.       插入一个对话框的资源,删除默认控件,并为对话框创建一个类,命名 ...

  5. MFC GDI绘图基础

    一.关于GDI的基本概念 什么是GDI? Windows绘图的实质就是利用Windows提供的图形设备接口GDI(Graphics Device Interface)将图形绘制在显示器上. 在Wind ...

  6. scxml 图像展示器 (基于C++ MFC GDI tinyxpath的实现)

    以前的时候学习新东西没有总结的习惯,周末把以前研究的东西翻了翻,稍微总结下. Scxml是w3c出来的基于状态机的对话脚本语言标准,具体内容可以谷歌到,这里讲述自己开发的一个把scxml转化为可交互图 ...

  7. GDI+编程说明及小结

    原文地址:http://blog.csdn.net/byxdaz/article/details/5972759 GDI+(Graphics Device Interface Plus图形设备接口加) ...

  8. MFC映射

    所有CDC输出函数最终都会输出到物理平面(屏幕窗口.打印纸等).这些物理平面的单位量化往往多种多样,比如像素.打印点.英寸.毫米等等.这样可能会造成很多混乱,所以CDC输出对所有物理平面进行统一抽象化 ...

  9. GDI+编程小结

    GDI+(Graphics Device Interface Plus图形设备接口加)是Windows XP和Windows Server 2003操作系统的子系统,也是.NET框架的重要组成部分,负 ...

随机推荐

  1. twitter storm源码走读之3--topology提交过程分析

    概要 storm cluster可以想像成为一个工厂,nimbus主要负责从外部接收订单和任务分配.除了从外部接单,nimbus还要将这些外部订单转换成为内部工作分配,这个时候nimbus充当了调度室 ...

  2. jQuery 判断表单中多个 input text 中至少有一个不为空

    html: 名称1:<input class="seasoning_name" type="text" name="seasoning_name ...

  3. an optimal solution to the problem

    http://www.personal.kent.edu/~rmuhamma/Algorithms/MyAlgorithms/Greedy/greedyIntro.htm Greedy Introdu ...

  4. os

    内核,Shell和文件结构一起形成了基本的操作系统结构. from:大学生攻克Linux系统教程(又名天下没有难学的Linux) 发问: 0-内核,再怎么分出层次呢?

  5. Andrew Ng机器学习公开课笔记–Reinforcement Learning and Control

    网易公开课,第16课 notes,12 前面的supervised learning,对于一个指定的x可以明确告诉你,正确的y是什么 但某些sequential decision making问题,比 ...

  6. [Android] Intent详解

    [转]http://www.cnblogs.com/engine1984/p/4146621.html [正文] Intent组件虽然不是四大组件,但却是连接四大组件的桥梁,学习好这个知识,也非常的重 ...

  7. DefaultHttpClient使用

    转自:http://username2.iteye.com/blog/1664995 博客分类:  java 工具类 javaio  ]; } json = JSONObject.fromObject ...

  8. SecureCRT SSH VMware Ubuntu

    Ubuntu 10.4 装完后网络OK. NAT模式下, 可以上网. 宿主机和客户机可以彼此ping通. 主要是检查SSH服务, 和防火墙是否关闭(UBUNTU 默认没有安装SSH, 默认启动了防火墙 ...

  9. pylint window下安装与使用

    简介 Pylint 是一个 Python 代码分析工具,它分析 Python 代码中的错误,查找不符合代码风格标准(Pylint 默认使用的代码风格是 PEP 8)和有潜在问题的代码. Pylint ...

  10. IOS 跳转时传参数的常用方法

    在iOS开发中常用的参数传递有以下几种方法: 采用代理模式 采用iOS消息机制 通过NSDefault存储(或者文件.数据库存储等) 通过AppDelegate定义全局变量(或者使用UIApplica ...