zoukankan      html  css  js  c++  java
  • VC++(.Net)GDIPlus的使用方法

    1、在stdafx.h中

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

    2、在APP.cpp中声明全局变量

    ULONG_PTR m_gdiplusToken;

    3、注意在App的InitInstance函数里, 在"INT_PTR nResponse = dlg.DoModal();"之前,添加下面的语句:

    GdiplusStartupInput m_gdiplusStartupInput;
    GdiplusStartup(&m_gdiplusToken, &m_gdiplusStartupInput, NULL);

    4、在App的ExitInstance()中调用:ExitInstance()函数在类的重写中添加

    GdiplusShutdown(m_gdiplusToken);

    5、一个使用的小例子:按钮触发画正弦波。基于对话框的MFC。

    void CGDITestDlg::OnBnClickedButtonDraw()
    {
    // TODO: 在此添加控件通知处理程序代码
    CClientDC dc(this);
    CRect rect;
    GetClientRect(&rect);
    dc.SetMapMode(MM_ANISOTROPIC);
    dc.SetWindowOrg(0,0);
    dc.SetWindowExt(rect.right,rect.bottom);
    dc.SetViewportOrg(0,rect.bottom/2);
    dc.SetViewportExt(rect.right/2,-rect.bottom);

    Graphics graphics(dc);
    Pen myPen(Color::Red);
    myPen.SetWidth(1);
    for(int i=0;i<rect.right;i++)
    graphics.DrawLine(&myPen,i,100*sin(2*(i/(rect.right/5.0))*3.14),i+1,100*sin(2*((i+1)/(rect.right/5.0))*3.14));
    myPen.SetColor(Color::Blue);
    graphics.DrawLine(&myPen, 0, 0, rect.right, 0);
    }

    运行结果:



     

  • 相关阅读:
    PHP“Cannot use object of type stdClass as array”
    JS简单循环遍历json数组的方法
    省市区、民族下拉列表框
    java 代码获取视频时长
    CentOs 相关
    曾经遇过的sql问题
    在线分享代码
    ssm 数据库连接池配置
    代码片段
    java 常见问题
  • 原文地址:https://www.cnblogs.com/chuanzifan/p/2264507.html
Copyright © 2011-2022 走看看