VS2008,GDIPlus初步

以VS2008 MDI为例,

 

step1.在文件stdafx.h中加入如下代码

 

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

 

#ifndef ULONG_PTR
#define ULONG_PRT unsigned long*
#endif

 

step2. 定义全局变量,如下所示.

 

// The one and only CPhotoMeterApp object

CPhotoMeterApp theApp;

 

//初始化gdiplus的环境
ULONG_PTR  gdiplusToken;

 

//......

 

step3.在InitInstance()函数初始化GDI+

 

 // Initialize GDI+.
 Gdiplus::GdiplusStartupInput  gdiplusStartupInput;
 Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

 

// Parse command line for standard shell commands, DDE, file open
 CCommandLineInfo cmdInfo;
 ParseCommandLine(cmdInfo);

 

step4.在ExitInstance()函数中销毁GDI+

 

//shutdown GDI+

 Gdiplus::GdiplusShutdown(gdiplusToken);

 

step5.在void CAboutDlg::OnPaint()举个GDI+绘制的例子

 

void CAboutDlg::OnPaint()
{
 CPaintDC dc(this); // device context for painting
 Graphics graphics(dc.GetSafeHdc());     //Graphics graphics(dc.m_hDC);也可以

 

CRect rect;
 GetDlgItem(IDC_STATIC_FRAME)->GetWindowRect(&rect);    //IDC_STATIC_FRAME是个picture控件,visible=false
 ScreenToClient(&rect);
  
 //Brush
 Gdiplus::LinearGradientBrush lingrbrush(Gdiplus::Rect(rect.left, rect.top, rect.Width(), rect.Height()),  //  绘制区域
  Color(250, 248,242,240),   //  第一种颜色
  Color(250, 255,255,255),   //  第二种颜色
  (Gdiplus::REAL)(270));    //  渐变色的角度

 graphics.FillRectangle(&lingrbrush, Gdiplus::Rect(rect.left,rect.top,rect.Width(),rect.Height() ) );
 
 Gdiplus::Pen pen(Color(255,145,155,156));
 Gdiplus::Pen penshade(Color(100,145,155,156));
 graphics.DrawRectangle(&pen,Gdiplus::Rect(rect.left,rect.top,rect.Width(),rect.Height()));
 graphics.DrawRectangle(&penshade,Gdiplus::Rect(rect.left,rect.top,rect.Width()+1,rect.Height()+1));

 // 不为绘图消息调用 CDialog::OnPaint()
}

 

 

 step6.贴图效果

 

 

 

 

step7.列外,CSDN的博客做的真TMD差劲.不兼容Chrome,写文章界面一点都不有好,还IT社区,一帮吃shi的,,,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值