今天再看官網推薦的Teechart的使用方式,感覺他們還是推薦使用VC++6.0的導出頭檔案格式,來引入所有的類,并操作teechart控件。
All the files necessary can be found under the New VC classes folder below the utilities folder; these files should be copied to your project folder (using Windows Explorer) and then should be added in to the project (in Solution Explorer -> right click over "Source Files" & "Header Files" folders -> Add Existing Item...).
長期使用teechart,2010年之前在Delphi使用,這幾年使用的是VC++。有段時間自繪了曲線顯示視窗,但是要處理的動作和效果實在是太多了,雖然可以自定義的東西很多,但是工作量實在是太大,現在已經是大齡程式員了,沒有那麼多的時間和精力去自己畫了,隻好重用teechart。
VS使用上的困惑:有幾個軟體用的是VS2005及以上版本開發的,但是因為在這些編譯器中teechart導出的函數接口有改動,導緻程式設計效率底下,附上VS2005--VS2015的類庫導入步驟:
添加相關類MFC Class From Typelib--->add class from registry---->available type libraries選中teechart pro activex control v8,後面會顯示具體的注冊路徑。把接口interfaces IAxes I...之類的全部選中,導入到程式中,就可以使用了。
下面對比VS和VC++6.0的導出檔案:
VS版本的導出檔案:
// Machine generated IDispatch wrapper class(es) created with Add Class from Typelib Wizard
#import "C:\\Windows\\SysWow64\\TeeChart8.ocx" no_namespace
// CAxes wrapper class
class CAxes : public COleDispatchDriver
{
public:
CAxes(){} // Calls COleDispatchDriver default constructor
CAxes(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
CAxes(const CAxes& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
// Attributes
public:
// Operations
public:
// IAxes methods
public:
LPDISPATCH get_Left()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Right()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Top()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
LPDISPATCH get_Bottom()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
BOOL get_Visible()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_Visible(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
LPDISPATCH get_Depth()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
BOOL get_DrawAxesBeforeSeries()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_DrawAxesBeforeSeries(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
long AddCustom(BOOL IsHorizontal)
{
long result;
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_METHOD, VT_I4, (void*)&result, parms, IsHorizontal);
return result;
}
LPDISPATCH get_Custom(long CustomAxisIndex)
{
LPDISPATCH result;
static BYTE parms[] = VTS_I4 ;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, parms, CustomAxisIndex);
return result;
}
long get_CustomCount()
{
long result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}
void RemoveCustom(long CustomAxisIndex)
{
static BYTE parms[] = VTS_I4 ;
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, parms, CustomAxisIndex);
}
void RemoveAllCustom()
{
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
LPDISPATCH get_DepthTop()
{
LPDISPATCH result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
return result;
}
BOOL get_FastCalc()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_FastCalc(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
void SetIsometric(long aVertical, long aHorizontal)
{
static BYTE parms[] = VTS_I4 VTS_I4 ;
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, parms, aVertical, aHorizontal);
}
void Hide()
{
InvokeHelper(, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}
BOOL get_Behind()
{
BOOL result;
InvokeHelper(, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}
void put_Behind(BOOL newValue)
{
static BYTE parms[] = VTS_BOOL ;
InvokeHelper(, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
// IAxes properties
public:
};
VC++6.0的的導出檔案如下:
#if !defined(AFX_AXES_H__6F4A532C_9E89_4968_9E14_E83C63437874__INCLUDED_)
#define AFX_AXES_H__6F4A532C_9E89_4968_9E14_E83C63437874__INCLUDED_
#if _MSC_VER >
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++
// NOTE: Do not modify the contents of this file. If this class is regenerated by
// Microsoft Visual C++, your modifications will be overwritten.
// Dispatch interfaces referenced by this interface
class CAxis;
/
// CAxes wrapper class
class CAxes : public COleDispatchDriver
{
public:
CAxes() {} // Calls COleDispatchDriver default constructor
CAxes(LPDISPATCH pDispatch) : COleDispatchDriver(pDispatch) {}
CAxes(const CAxes& dispatchSrc) : COleDispatchDriver(dispatchSrc) {}
// Attributes
public:
// Operations
public:
CAxis GetLeft();
CAxis GetRight();
CAxis GetTop();
CAxis GetBottom();
BOOL GetVisible();
void SetVisible(BOOL bNewValue);
CAxis GetDepth();
BOOL GetDrawAxesBeforeSeries();
void SetDrawAxesBeforeSeries(BOOL bNewValue);
long AddCustom(BOOL IsHorizontal);
CAxis GetCustom(long CustomAxisIndex);
long GetCustomCount();
void RemoveCustom(long CustomAxisIndex);
void RemoveAllCustom();
CAxis GetDepthTop();
BOOL GetFastCalc();
void SetFastCalc(BOOL bNewValue);
void SetIsometric(long aVertical, long aHorizontal);
void Hide();
BOOL GetBehind();
void SetBehind(BOOL bNewValue);
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_AXES_H__6F4A532C_9E89_4968_9E14_E83C63437874__INCLUDED_)
幾大變化:
VC++ 6.0 | VS2005及更高版本 | |
---|---|---|
頭檔案和源檔案 | | axes.h |
函數名稱1 | | get_Left() |
函數傳回值1 | | LPDISPATCH |
函數名稱2 | | put_Behind(BOOL newValue) |
函數傳回值2 | | void |
語句的不同
VC++ 6.0 | VS2005及更高版本 | |
---|---|---|
語句1 | `mChart.GetAxis().GetLeft().SetVisible(FALSE); | ((CAxis)((CAxes)mChart.get_Axis()).get_Left()).put_Visible(FALSE);` |
語句2 | | CAxes ChartAxis = mChart.get_Axis(); CAxis asLeft = ChartAxis.get_Left(); asLeft.put_Visible(FALSE); |
使用高版本的VS導出的頭檔案使用過程比較繁瑣,尤其是傳回值,需要查詢具體的類型。
官網推薦還是使用VC++6.0的版本,并且附上了一個檔案夾,可以直接使用
New VC Classes
具體的使用過程還是查詢
Tutorial 15 - MS VC++ Applications
官方文檔中幾個有用的例子:
标題的更改
#include "Titles.h"
#include "Strings.h"
COleVariant var1(CString ("ACME Monthly Sales"));
COleVariant var2(CString ("Year: 2014"));
CTitles hd = m_Chart.GetHeader();
hd.GetText().Clear();
hd.GetText().Add(*(LPCVARIANT)var1);
hd.GetText().Add(*(LPCVARIANT)var2);
//if items (header lines) already in list (+ alternative COleVariant declare syntax)
m_Chart1.GetHeader().GetText().SetItem(, COleVariant("ACME Monthly Sales"));
m_Chart1.GetHeader().GetText().SetItem(, COleVariant("Year: 2014"));
Canvas繪圖
#include "Canvas.h"
m_Chart1.GetCanvas().MoveTo(,);
m_Chart1.GetCanvas().LineTo(,);
m_Chart1.GetCanvas().TextOut(,,"My output text");
坐标軸label的文字修改
CString strLabel(*LabelText);
strLabel += " Period";
strLabel.SetSysString(LabelText);
坐标軸label 的數值更改
{
if (Axis == atLeft)
{
*MoreLabels = true;
//Only label if following cases are true
switch( LabelIndex )
{
case : *LabelValue = ; break;
case : *LabelValue = ; break;
case : *LabelValue = ; break;
default: *MoreLabels=false;
}
}
}
界面繪圖:
CString text;
int value1,value2,total;
value1 = ;
value2 = ;
total = value1+value2;
text.Format(_T("Serie : %d"),total);
m_Chart1.GetCanvas().TextOut(,,text));
常量定義部分:官方給出一個頭檔案
TeeChartDefines.h
,為什麼不能通過添加類的方式引入,原因是MS VC++ doesn't natively support import of TeeChart constants. You need to create you own defines file and #include it in your project. We offer a pre built defines file in the Examples\Visual C++ folder. Including the file in your project will allow you to use constants by name as matching the Enum declarations in the Online help file.
附上幾個常見問題的解答:
MicroSoft Visual C++ specific
- How to use TeeChart constants in MS VC++.
- Where are descriptions of functions such as GetSeries(), Add() and other similar functions?
- Changes made at design time with the Chart Editor do not always save.
- How do I add/change text of the Chart Header and Footer at runtime in MS VC++ ?
- Can I obtain any additional examples with use of TeeChart Pro for VC++?