65.9K
CodeProject 正在变化。 阅读更多。
Home

CE 的实时 2D 图形

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.20/5 (4投票s)

2001 年 11 月 14 日

CPOL

1分钟阅读

viewsIcon

187632

downloadIcon

1446

适用于 CE 的 2D 图表。要运行此应用程序,您必须安装 eMbedded Visual C++ 3.0。

Sample Image - Graph.jpg

引言

本文介绍如何开发实时 2D 图表。我一直在网上搜索如何开发如上所示的图表。我发现 Microsoft Visual Studio 使用图片控件来绘制图表。为了开发此应用程序,我需要使用 Microsoft eMbedded Visual C++ 3.0。

过去,我通过不断更新数值数组来显示“实时”仪表读数。该图表显示了来自仪器的实时数据。

这个 MECGraphCtrl 基于 Mark C. Malburg 使用的位图重绘概念。它通过显示缩放信息和绘制双精度值提供了显著的增强。用户实现如下所述。

在控件的所有者(例如,对话框)中插入一个虚拟图片控件。将自定义控件的边框大小调整为 GraphCtrl 的所需大小。将控件命名为听起来很技术性的名称,例如“IDC_GRAPH_CUSTOM”。在自定义控件的属性中,对于“类”,写入“GRAPH_CUSTOM”。这是在对话框类的构造函数中应注册的类字符串。

1. 在所有者类中插入控件。

添加一个类型为 MECGraphCtrl 的成员变量。

class MECPerformerDlg : public CDialog
{
  // Construction
  ...
protected:
  static BOOL RegisterWndClass(HINSTANCE hInstance);
  MECGraphCtrl m_oGraphCtrl;  
}

2. 注册自定义控件。

BOOL MECPerformerDlg::OnInitDialog()
{
	WNDCLASS wc;
	wc.lpszClassName = _T("GRAPH_CUSTOM"); // matches class name 
	wc.hInstance = hInstance;
	wc.lpfnWndProc = ::DefWindowProc;
	//wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	wc.hIcon = 0;
	wc.lpszMenuName = NULL;
	wc.hbrBackground = (HBRUSH) ::GetStockObject(LTGRAY_BRUSH);
	wc.style = CS_GLOBALCLASS; // To be modified
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
}

3. 创建控件。

BOOL MECPerformerDlg::OnInitDialog()
{
	...
	CRect rect;
	GetDlgItem(IDC_GRAPH_CUSTOM)->GetWindowRect(rect) ;
	ScreenToClient(rect) ;
	GetDlgItem(IDC_GRAPH_CUSTOM)->ShowWindow(SW_HIDE);

	// create the control
	m_oGraphCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ; 
	...
}

4. 个性化控件

设置垂直范围、背景颜色、网格颜色和绘图颜色。

BOOL MECPerformerDlg::OnInitDialog()
{
  ...
  // determine the rectangle for the control
  CRect rect;
  GetDlgItem(IDC_GRAPH_CUSTOM)->GetWindowRect(rect) ;
  ScreenToClient(rect) ;
  GetDlgItem(IDC_GRAPH_CUSTOM)->ShowWindow(SW_HIDE);

  // create the control
  m_oGraphCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this) ; 
  m_oGraphCtrl.SetXRange(0,10,2);
  m_oGraphCtrl.SetRange(0, 10, 2) ;

  m_oGraphCtrl.SetYUnits("Volume in ml") ;
  m_oGraphCtrl.SetXUnits("Time in seconds") ;
  m_oGraphCtrl.SetBackgroundColor(RGB(0, 0, 64)) ;
  m_oGraphCtrl.SetGridColor(RGB(192, 192, 255)) ;
  m_oGraphCtrl.SetPlotColor(RGB(0, 255, 0)) ;
  ...
}

5. 使用控件。

使用要附加到绘图的数据值调用 m_oGraphCtrl.AppendPoint(nRandomX, nRandomY); 函数。

可以修改值以实现不同的显示样式。

© . All rights reserved.