17.6.5 测试GDI+搭建的环境(2)
2.在对话框应用程序中使用GDI+
- 01 void CDialogGDIDlg::OnPaint()
- 02 {
- 03 CPaintDC dc(this); //绘图设备上下文环境
- 04 using namespace Gdiplus;
- 05 Graphics graphics(dc.m_hDC);
- 06 Pen newPen(Color(0,255,0),3);
- 07 //创建一个填充画刷,前景色为红色,背景色为蓝色
- 08 HatchBrush newBrush(HatchStyleCross,Color(255,255,0,0),Color(255,
- 0,0,255));
- 09 //在(10,10)处绘制一个长为200,高为100的矩形
- 10 graphics.DrawRectangle(&newPen,10,10,200,100);
- 11 //在(10,10)处填充一个长为200,高为100的矩形区域
- 12 graphics.FillRectangle(&newBrush,10,10,200,100);
- 13 }
编译并运行,结果如图17.20所示。
|
| 图17.20 对话框GDI+程序运行结果 |