VC2008中MFC使用GDI+

5 篇文章 0 订阅
做了个图形界面程序来显示定位结果,第一次用GDI+,费了百度谷歌九牛二虎之力,才搞出了这么个小小程序,

VC2008中MFC使用GDI+的步骤如下:

首先包含以下头文件和lib库:

#include <gdiplus.h>
#pragma comment (lib, "gdiplus.lib")

然后添加两个变量到窗口类里:

using namespace Gdiplus;

在初始化函数里增加:

Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);

2. OK可以画图了:

int X0_Room=100, Y0_Room=100, Width_Room=200, Height_Room=200;
CRect       RectForm;  
GetClientRect(&RectForm);  
Bitmap      bmp(RectForm.right,RectForm.bottom);  
Graphics    GraphBuf(&bmp);  
Pen redPen(Color(250,0,0));

//buf.Clear(Color(128,128,128));
int FontSize = 20;
FontFamily  fontFamily(_T("幼圆"));
Gdiplus::Font   font(&fontFamily, FontSize, FontStyleRegular, UnitPoint);

SolidBrush  GrayBrush(Color::DarkGray);
SolidBrush  YelloBrush(Color::Yellow);
CString     TextStr = _T("A区");
PointF      TextXY(0, 0);

TextXY.X = X0_Room + Width_Room/2 - TextStr.GetLength()*FontSize/2;
TextXY.Y = Y0_Room - FontSize - 15;
GraphBuf.DrawString(TextStr, TextStr.GetLength(), &font, TextXY, &GrayBrush);
TextStr = _T("B区");
TextXY.X = TextXY.X + Width_Room;
GraphBuf.DrawString(TextStr, TextStr.GetLength(), &font, TextXY, &GrayBrush);
GraphBuf.DrawRectangle(&redPen, X0_Room,    Y0_Room,    Width_Room, Height_Room);
GraphBuf.DrawRectangle(&redPen, X0_Room+Width_Room, Y0_Room,    Width_Room, Height_Room);

Graphics    Graph_ShowOnWindow(this->GetDC()->m_hDC);
Graph_ShowOnWindow.DrawImage(&bmp,0,0);

3. 在退出时调用:

GdiplusShutdown(m_gdiplusToken);// 关闭GDI+的调用


PS:
以前我觉得VC画图很费劲,画条简单的线都要罗里吧嗦写一大堆的代码,跟C++Builder相比简直就是不胜其烦;
现在在MFC里面用GDI+,略微有点方便,希望微软的VC以后朝着强大的RAD开发工具迈进,把这些东西都简化简化,
该可搞个控件的东西就搞个控件,比如定时器,控件直观又方便,比那些消息啊、MFC类啊好用多了!
最好达到像VB那样方便快捷的开发,当然功能要保持强大。




评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值