首页 > 其他分享 >VS2008,GDIPlus初步

VS2008,GDIPlus初步

时间:2022-12-13 18:05:00浏览次数:39  
标签:Width VS2008 Gdiplus 初步 GDIPlus Rect graphics GDI rect


以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.贴图效果

 

VS2008,GDIPlus初步_shell

 

 

 

标签:Width,VS2008,Gdiplus,初步,GDIPlus,Rect,graphics,GDI,rect
From: https://blog.51cto.com/u_15911341/5934948

相关文章