• 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);  
    
    }
  • 相关阅读:
    投简历——个人记录
    光电经纬仪——查资料
    Spring Boot(十三):spring boot小技巧
    Spring Boot(十二):spring boot如何测试打包部署
    Python3 hasattr()、getattr()、setattr()函数简介
    Python3 格式化字符串
    Python3 join函数和os.path.join用法
    Python3 根据m3u8下载视频,批量下载ts文件并且合并
    it commit提示Your branch is up-to-date with 'origin/master'.
    git下,输入git log 进入log 怎么退出
  • 原文地址:https://www.cnblogs.com/chenzuoyou/p/3298182.html
Copyright © 2020-2023  润新知