VC.net中使用GDI+的方法
2009-06-20 23:05
531 查看
(1)、在应用程序中添加GDI+的包含文件gdiplus.h以及附加的类库gdiplus.lib。通常gdiplus.h包含文件
添加在应用程序的stdafx.h文件中,而gdiplus.lib可用两种进行添加:第一种是直接在stdafx.h文件中
添加下列语句:
#pragma comment( lib, "gdiplus.lib" )
另一种方法是:选择"项目->属性"菜单命令,在弹出的对话框中选中左侧的"链接器->输入"选项,在
右侧的"附加依赖项"框中键入gdiplus.lib,
(2)、在应用程序项目的应用类中,添加一个成员变量,如下列代码:
ULONG_PTR m_gdiplusToken;
其中,ULONG_PTR是一个DWORD数据类型,该成员变量用来保存GDI+被初始化后在应用程序中的GDI+标识,
以便能在应用程序退出后,引用该标识来调用Gdiplus:: GdiplusShutdown来关闭GDI+。
(3)、在应用类中添加ExitInstance的重载,并添加下列代码用来关闭GDI+:
int CGDIPlusApp::ExitInstance()
{
Gdiplus::GdiplusShutdown(m_gdiplusToken);
return CWinApp::ExitInstance();
}
(4)、在应用类的InitInstance函数中添加GDI+的初始化代码: BOOL CGDIPlusApp::InitInstance()
{
CWinApp::InitInstance();
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
...
}
(5)、在需要绘图的窗口或视图类中添加GDI+的绘制代码: void CGDIPlusView::onDraw(CDC *pDC)
{
Graphics graphics( pDC->m_hDC );
GraphicsPath path; // 构造一个路径
path.AddEllipse(50, 50, 200, 100);
// 使用路径构造一个画刷
PathGradientBrush pthGrBrush(&path);
// 将路径中心颜色设为蓝色
pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));
// 设置路径周围的颜色为蓝芭,但alpha值为0
Color colors[] = {Color(0, 0, 0, 255)};
INT count = 1;
pthGrBrush.SetSurroundColors(colors, &count);
graphics.FillRectangle(&pthGrBrush, 50, 50, 200, 100);
LinearGradientBrush linGrBrush(
Point(300, 50),
Point(500, 150),
Color(255, 255, 0, 0), // 红色
Color(255, 0, 0, 255)); // 蓝色
graphics.FillRectangle(&linGrBrush, 300, 50, 200, 100);
}
添加在应用程序的stdafx.h文件中,而gdiplus.lib可用两种进行添加:第一种是直接在stdafx.h文件中
添加下列语句:
#pragma comment( lib, "gdiplus.lib" )
另一种方法是:选择"项目->属性"菜单命令,在弹出的对话框中选中左侧的"链接器->输入"选项,在
右侧的"附加依赖项"框中键入gdiplus.lib,
(2)、在应用程序项目的应用类中,添加一个成员变量,如下列代码:
ULONG_PTR m_gdiplusToken;
其中,ULONG_PTR是一个DWORD数据类型,该成员变量用来保存GDI+被初始化后在应用程序中的GDI+标识,
以便能在应用程序退出后,引用该标识来调用Gdiplus:: GdiplusShutdown来关闭GDI+。
(3)、在应用类中添加ExitInstance的重载,并添加下列代码用来关闭GDI+:
int CGDIPlusApp::ExitInstance()
{
Gdiplus::GdiplusShutdown(m_gdiplusToken);
return CWinApp::ExitInstance();
}
(4)、在应用类的InitInstance函数中添加GDI+的初始化代码: BOOL CGDIPlusApp::InitInstance()
{
CWinApp::InitInstance();
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
...
}
(5)、在需要绘图的窗口或视图类中添加GDI+的绘制代码: void CGDIPlusView::onDraw(CDC *pDC)
{
Graphics graphics( pDC->m_hDC );
GraphicsPath path; // 构造一个路径
path.AddEllipse(50, 50, 200, 100);
// 使用路径构造一个画刷
PathGradientBrush pthGrBrush(&path);
// 将路径中心颜色设为蓝色
pthGrBrush.SetCenterColor(Color(255, 0, 0, 255));
// 设置路径周围的颜色为蓝芭,但alpha值为0
Color colors[] = {Color(0, 0, 0, 255)};
INT count = 1;
pthGrBrush.SetSurroundColors(colors, &count);
graphics.FillRectangle(&pthGrBrush, 50, 50, 200, 100);
LinearGradientBrush linGrBrush(
Point(300, 50),
Point(500, 150),
Color(255, 255, 0, 0), // 红色
Color(255, 0, 0, 255)); // 蓝色
graphics.FillRectangle(&linGrBrush, 300, 50, 200, 100);
}
相关文章推荐
- VC++ 6.0 控制台程序使用GDI+的方法
- VC.net中使用GDI+的方法
- VC中使用GDI+的配置方法概述
- 在VC使用GDI+的配置方法
- 在VC使用GDI+的配置方法
- 在VC使用GDI+的配置方法
- 在VC使用GDI+的配置方法
- <@乌龟:>VC++2005以上使用.Net的方法
- VC静态链接库的使用方法 以及jsoncpp使用方法
- .net中事务使用方法
- FCKeditor在.net(asp.net)中的使用方法。
- .net 使用JQuery 调用Ashx 后面直接写方法名,通过反射找到对应的方法
- [翻译]在SQL Server中使用CLR调用.NET方法 (转)
- Visual C++6.0使用GDI+的一般方法
- .net学习之多线程、线程死锁、线程通信 生产者消费者模式、委托的简单使用、GDI(图形设计接口)常用的方法
- cygwin跨平台移植 gcc+vc联合使用的方法和注意事项
- [翻译]在SQL Server中使用CLR调用.NET方法
- VC++ MFC SQL ADO数据库访问技术使用的基本步骤及方法
- 在VC中使用GDI+从自定义资源中加载图片
- android.net.wifi的简单使用方法