zoukankan      html  css  js  c++  java
  • VC GDI+基础用法VC

    #include "GdiPlus.h"
    
    // 使用GDI+ 命名空间
    using namespace Gdiplus;
    
    // 与GDI+ 相关的其它头文件,如:GraphicsPath类所在的头文件
    #include "GdiplusBase.h"
    #include "GdiPlusPath.h"
    
    // 导入GDI+ lib文件
    #pragma comment(lib, "GdiPlus.lib")
    
    // GDI+ 资源的初始化与销毁
    
    // 全局变量,表明对GDI+的一个引用
    ULONG_PTR m_gdiplusToken;
    
    //  在使用GDI+ 的类或窗口的构造函数里初始化GDI+的资源
    
    CTestGraphicsView::CTestGraphicsView()
    {
     Gdiplus::GdiplusStartupInput gdiplusStartupInput;
     // TODO: Initial GDI+ related handler 初始化GDI+相关句柄
     Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
    }
    
    //  在使用GDI+ 的类或窗口的析构函数里销毁GDI+的资源
    
    CTestGraphicsView::~CTestGraphicsView()
    {
     Gdiplus::GdiplusShutdown(m_gdiplusToken);
    }
    
    ///////////////构造Graphics对象//////////////////////
    
    ------------------------------------在单文档的OnDraw()函数里构造Graphics对象-------------------------------
    
    void CTestGraphicsView::OnDraw(CDC* pDC)
    {
     CTestGraphicsDoc* pDoc = GetDocument();
     ASSERT_VALID(pDoc);
     if (!pDoc)
      return;
    
     // TODO: 在此处为本机数据添加绘制代码 
     Graphics g(pDC->m_hDC);
    
     GraphicsPath path;
     path.AddRectangle(Rect(40,10,200,50));
     g.DrawPath(&Pen(Color.Red),&path);
    
    }
    
     
    
    ---------------------------------------在对话框的OnPaint()函数里构造Graphics对象--------------------------
    
    void CTestGraphicsView::OnPaint() 
    {
     CPaintDC dc(this); // device context for painting
    
     OnDrawGraph(&dc); 
    }
    
    void CTestGraphicsView::OnDrawGraph(CDC *pDC) 
    {
     Graphics g(pDC->m_hDC);
    
     GraphicsPath path;
     path.AddRectangle(Rect(40,10,200,50));
     g.DrawPath(&Pen(Color.Red),&path);  
    
    }
  • 相关阅读:
    02-三种布局方式/触屏事件/BFC
    02-单点登录(移动端)
    02-转>>chunk-vendors过大导致首屏加载太慢的优化
    15-转>pc端和h5端多页面配置
    14-转>publicPath
    04-GitHub上上传自己的项目
    03-合并到master后打tag
    final关键字
    重载(Overloading)与覆写(Override)的区别?
    腾讯微博
  • 原文地址:https://www.cnblogs.com/chenzuoyou/p/3298182.html
Copyright © 2011-2022 走看看