做了个图形界面程序来显示定位结果,第一次用GDI+,费了百度谷歌九牛二虎之力,才搞出了这么个小小程序,
在初始化函数里增加:
2. OK可以画图了:
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那样方便快捷的开发,当然功能要保持强大。