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

条形图控件

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.62/5 (23投票s)

2004年1月27日

viewsIcon

113647

downloadIcon

4142

从 CStatic 派生的简单条形图控件类

引言

这是一个简单的条形图控件类,它继承自 CStatic。它支持显示实时数据,使用任意数量的条形,具有不同的颜色,使用厘米和英寸两种刻度等。

使用代码

如何将此控件添加到您的项目中

  1. 将文件 GraphCtrl.hGraphCtrl.cpp 复制到您的项目目录,并添加到您的项目中。
  2. 在需要使用此类的文件中包含 GraphCtrl.h
  3. CStatic 定义更改为 CGraphCtrl
  4. 使用下面描述的 API。
int SetNumberOfBars(int num)
//Sets the number of bars you want to display. 
//If successful, it returns number of bars set, otherwise -1.
int SetBarColor(int idx, COLORREF clr)
//Sets the color for the bars.  idx is the index of the 
//bar from left to right (1,2,3..etc.)
//If successful, it returns index of the bar for which 
//the color was set, otherwise -1.
void SetUnit(int unit)
//Sets the scale to cm or inch. Send UCM for cm and UINCH for inch
void SetBarValue(int idx, int value)
//Sets the value of a bar.  idx is the index of the bar 
//for which the value to be set and 
//the parameter value is the value we have to set for it.

使用示例

m_Graph.SetNumberOfBars(18); //Number of bars to be shown

m_Graph.SetBarColor(1,RGB(200,200,200)); 
    //Sets the color to the bar of index 1

m_Graph.SetBarValue(1,22); //Sets value to the bar of index 1

m_Graph.SetUnit(UCM);  //Sets scale to cm
© . All rights reserved.