MsChart控件在VC++中的使用

时间:2023-02-02 14:38:53

关于MsChart控件的注册:

32位系统之下

1.mschrt20.ocx放在windows/system32目录下。注意,这个文件名中的没有字母a,即没有写chart中的字母a,就是这一细节让我多花了不少时间。

2.使用命令regsvr32 MSCHRT20.OCX来注册。









64位系统下

1.确保win7管理员权限


2.OCX控件,放到C:\Windows\SysWow64路径下面


3.进入cmd,管理员权限运行


4.regsvr32C:\Windows\SysWow64\MSCHRT20.OCX


注册成功会有提示的。


可以使用反注册来验证。


regsvr32 MSCHRT20.OCX /u  //清除


PS:注册出现问题时,很大原因是没有以管理员身份运行cmd



注册完成以后,就可以使用了。

很多的资料上说,先包含头文件

<span style="font-family:KaiTi_GB2312;font-size:18px;">#include "vcbackdrop.h"
#include "vcfill.h"
#include "vcbrush.h"
#include "vcaxis.h"
#include "vcaxisgrid.h"
#include "vcaxisscale.h"
#include "vcplot.h"
#include "vcvaluescale.h"
#include "vcseriescollection.h"
#include "vcseries.h"
#include "vcpen.h"
#include "vccolor.h"
#include "vccategoryscale.h"
#include "vcaxistitle.h"
#include "vcdatagrid.h"
#include "vcdatapoint.h"
#include "vcdatapoints.h"
#include "vcdatapointlabel.h"</span>

但并没有提供头文件的代码,头文件代码下载地址:http://download.csdn.net/detail/u014023993/8203443

将这些类添加到自己的工程就可以了。


CMSChart类

<span style="font-family:KaiTi_GB2312;font-size:18px;">#if !defined(AFX_MSCHART_H__93A82E05_CA08_483A_8512_6446AA3EA1CC__INCLUDED_)
#define AFX_MSCHART_H__93A82E05_CA08_483A_8512_6446AA3EA1CC__INCLUDED_

#if _MSC_VER > 1000
#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 CVcTitle;
class CVcFootnote;
class CVcBackdrop;
class CVcLegend;
class CVcDataGrid;
class CVcPlot;

/////////////////////////////////////////////////////////////////////////////
// CMSChart wrapper class

class CMSChart : public CWnd
{
protected:
DECLARE_DYNCREATE(CMSChart)
public:
CLSID const& GetClsid()
{
static CLSID const clsid
= { 0x3a2b370c, 0xba0a, 0x11d1, { 0xb1, 0x37, 0x0, 0x0, 0xf8, 0x75, 0x3f, 0x5d } };
return clsid;
}
virtual BOOL Create(LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd, UINT nID,
CCreateContext* pContext = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
const RECT& rect, CWnd* pParentWnd, UINT nID,
CFile* pPersist = NULL, BOOL bStorage = FALSE,
BSTR bstrLicKey = NULL)
{ return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
pPersist, bStorage, bstrLicKey); }

// Attributes
public:

// Operations
public:
BOOL GetAutoIncrement();
void SetAutoIncrement(BOOL bNewValue);
BOOL GetRandomFill();
void SetRandomFill(BOOL bNewValue);
long GetChartType();
void SetChartType(long nNewValue);
short GetColumn();
void SetColumn(short nNewValue);
short GetColumnCount();
void SetColumnCount(short nNewValue);
CString GetColumnLabel();
void SetColumnLabel(LPCTSTR lpszNewValue);
short GetColumnLabelCount();
void SetColumnLabelCount(short nNewValue);
short GetColumnLabelIndex();
void SetColumnLabelIndex(short nNewValue);
CString GetData();
void SetData(LPCTSTR lpszNewValue);
CString GetFootnoteText();
void SetFootnoteText(LPCTSTR lpszNewValue);
BOOL GetRepaint();
void SetRepaint(BOOL bNewValue);
short GetRow();
void SetRow(short nNewValue);
short GetRowCount();
void SetRowCount(short nNewValue);
CString GetRowLabel();
void SetRowLabel(LPCTSTR lpszNewValue);
short GetRowLabelCount();
void SetRowLabelCount(short nNewValue);
short GetRowLabelIndex();
void SetRowLabelIndex(short nNewValue);
short GetSeriesColumn();
void SetSeriesColumn(short nNewValue);
long GetSeriesType();
void SetSeriesType(long nNewValue);
BOOL GetShowLegend();
void SetShowLegend(BOOL bNewValue);
long GetDrawMode();
void SetDrawMode(long nNewValue);
long GetBorderStyle();
void SetBorderStyle(long nNewValue);
BOOL GetEnabled();
void SetEnabled(BOOL bNewValue);
long GetHWnd();
CVcTitle GetTitle();
CVcFootnote GetFootnote();
CString GetTitleText();
void SetTitleText(LPCTSTR lpszNewValue);
BOOL GetStacking();
void SetStacking(BOOL bNewValue);
long GetTextLengthType();
void SetTextLengthType(long nNewValue);
BOOL GetAllowSelections();
void SetAllowSelections(BOOL bNewValue);
BOOL GetAllowSeriesSelection();
void SetAllowSeriesSelection(BOOL bNewValue);
BOOL GetAllowDynamicRotation();
void SetAllowDynamicRotation(BOOL bNewValue);
short GetActiveSeriesCount();
CVcBackdrop GetBackdrop();
CVcLegend GetLegend();
CVcDataGrid GetDataGrid();
CVcPlot GetPlot();
BOOL GetAllowDithering();
void SetAllowDithering(BOOL bNewValue);
BOOL GetDoSetCursor();
void SetDoSetCursor(BOOL bNewValue);
BOOL GetChart3d();
VARIANT GetChartData();
void SetChartData(const VARIANT& newValue);
long GetMousePointer();
void SetMousePointer(long nNewValue);
void Refresh();
void EditPaste();
void EditCopy();
void Layout();
void ToDefaults();
void SelectPart(short part, short index1, short index2, short index3, short index4);
void GetSelectedPart(short* part, short* index1, short* index2, short* index3, short* index4);
void TwipsToChartPart(long xVal, long yVal, short* part, short* index1, short* index2, short* index3, short* index4);
long GetOLEDragMode();
void SetOLEDragMode(long nNewValue);
long GetOLEDropMode();
void SetOLEDropMode(long nNewValue);
void OLEDrag();
LPUNKNOWN GetDataSource();
void SetRefDataSource(LPUNKNOWN newValue);
CString GetDataMember();
void SetDataMember(LPCTSTR lpszNewValue);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MSCHART_H__93A82E05_CA08_483A_8512_6446AA3EA1CC__INCLUDED_)
</span>


<span style="font-family:KaiTi_GB2312;font-size:18px;">// 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.


#include "stdafx.h"
#include "mschart.h"

// Dispatch interfaces referenced by this interface
#include "vctitle.h"
#include "vcfootnote.h"
#include "vcbackdrop.h"
#include "vclegend.h"
#include "vcdatagrid.h"
#include "vcplot.h"

/////////////////////////////////////////////////////////////////////////////
// CMSChart

IMPLEMENT_DYNCREATE(CMSChart, CWnd)

/////////////////////////////////////////////////////////////////////////////
// CMSChart properties

/////////////////////////////////////////////////////////////////////////////
// CMSChart operations

BOOL CMSChart::GetAutoIncrement()
{
BOOL result;
InvokeHelper(0x1, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetAutoIncrement(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x1, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

BOOL CMSChart::GetRandomFill()
{
BOOL result;
InvokeHelper(0x2, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetRandomFill(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x2, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

long CMSChart::GetChartType()
{
long result;
InvokeHelper(0x3, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetChartType(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x3, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

short CMSChart::GetColumn()
{
short result;
InvokeHelper(0x4, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetColumn(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0x4, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

short CMSChart::GetColumnCount()
{
short result;
InvokeHelper(0x5, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetColumnCount(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0x5, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

CString CMSChart::GetColumnLabel()
{
CString result;
InvokeHelper(0x6, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}

void CMSChart::SetColumnLabel(LPCTSTR lpszNewValue)
{
static BYTE parms[] =
VTS_BSTR;
InvokeHelper(0x6, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}

short CMSChart::GetColumnLabelCount()
{
short result;
InvokeHelper(0x7, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetColumnLabelCount(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0x7, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

short CMSChart::GetColumnLabelIndex()
{
short result;
InvokeHelper(0x8, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetColumnLabelIndex(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0x8, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

CString CMSChart::GetData()
{
CString result;
InvokeHelper(0x9, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}

void CMSChart::SetData(LPCTSTR lpszNewValue)
{
static BYTE parms[] =
VTS_BSTR;
InvokeHelper(0x9, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}

CString CMSChart::GetFootnoteText()
{
CString result;
InvokeHelper(0xa, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}

void CMSChart::SetFootnoteText(LPCTSTR lpszNewValue)
{
static BYTE parms[] =
VTS_BSTR;
InvokeHelper(0xa, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}

BOOL CMSChart::GetRepaint()
{
BOOL result;
InvokeHelper(0xb, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetRepaint(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0xb, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

short CMSChart::GetRow()
{
short result;
InvokeHelper(0xc, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetRow(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0xc, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

short CMSChart::GetRowCount()
{
short result;
InvokeHelper(0xd, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetRowCount(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0xd, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

CString CMSChart::GetRowLabel()
{
CString result;
InvokeHelper(0xe, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}

void CMSChart::SetRowLabel(LPCTSTR lpszNewValue)
{
static BYTE parms[] =
VTS_BSTR;
InvokeHelper(0xe, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}

short CMSChart::GetRowLabelCount()
{
short result;
InvokeHelper(0xf, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetRowLabelCount(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0xf, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

short CMSChart::GetRowLabelIndex()
{
short result;
InvokeHelper(0x10, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetRowLabelIndex(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0x10, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

short CMSChart::GetSeriesColumn()
{
short result;
InvokeHelper(0x11, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

void CMSChart::SetSeriesColumn(short nNewValue)
{
static BYTE parms[] =
VTS_I2;
InvokeHelper(0x11, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

long CMSChart::GetSeriesType()
{
long result;
InvokeHelper(0x12, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetSeriesType(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x12, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

BOOL CMSChart::GetShowLegend()
{
BOOL result;
InvokeHelper(0x13, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetShowLegend(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x13, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

long CMSChart::GetDrawMode()
{
long result;
InvokeHelper(0x17, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetDrawMode(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x17, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

long CMSChart::GetBorderStyle()
{
long result;
InvokeHelper(DISPID_BORDERSTYLE, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetBorderStyle(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(DISPID_BORDERSTYLE, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

BOOL CMSChart::GetEnabled()
{
BOOL result;
InvokeHelper(DISPID_ENABLED, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetEnabled(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(DISPID_ENABLED, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

long CMSChart::GetHWnd()
{
long result;
InvokeHelper(DISPID_HWND, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

CVcTitle CMSChart::GetTitle()
{
LPDISPATCH pDispatch;
InvokeHelper(0x1a, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL);
return CVcTitle(pDispatch);
}

CVcFootnote CMSChart::GetFootnote()
{
LPDISPATCH pDispatch;
InvokeHelper(0x1b, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL);
return CVcFootnote(pDispatch);
}

CString CMSChart::GetTitleText()
{
CString result;
InvokeHelper(0x1c, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}

void CMSChart::SetTitleText(LPCTSTR lpszNewValue)
{
static BYTE parms[] =
VTS_BSTR;
InvokeHelper(0x1c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}

BOOL CMSChart::GetStacking()
{
BOOL result;
InvokeHelper(0x1d, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetStacking(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x1d, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

long CMSChart::GetTextLengthType()
{
long result;
InvokeHelper(0x1e, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetTextLengthType(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x1e, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

BOOL CMSChart::GetAllowSelections()
{
BOOL result;
InvokeHelper(0x20, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetAllowSelections(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x20, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

BOOL CMSChart::GetAllowSeriesSelection()
{
BOOL result;
InvokeHelper(0x21, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetAllowSeriesSelection(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x21, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

BOOL CMSChart::GetAllowDynamicRotation()
{
BOOL result;
InvokeHelper(0x22, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetAllowDynamicRotation(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x22, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

short CMSChart::GetActiveSeriesCount()
{
short result;
InvokeHelper(0x23, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
return result;
}

CVcBackdrop CMSChart::GetBackdrop()
{
LPDISPATCH pDispatch;
InvokeHelper(0x24, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL);
return CVcBackdrop(pDispatch);
}

CVcLegend CMSChart::GetLegend()
{
LPDISPATCH pDispatch;
InvokeHelper(0x26, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL);
return CVcLegend(pDispatch);
}

CVcDataGrid CMSChart::GetDataGrid()
{
LPDISPATCH pDispatch;
InvokeHelper(0x27, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL);
return CVcDataGrid(pDispatch);
}

CVcPlot CMSChart::GetPlot()
{
LPDISPATCH pDispatch;
InvokeHelper(0x28, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&pDispatch, NULL);
return CVcPlot(pDispatch);
}

BOOL CMSChart::GetAllowDithering()
{
BOOL result;
InvokeHelper(0x2b, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetAllowDithering(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x2b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

BOOL CMSChart::GetDoSetCursor()
{
BOOL result;
InvokeHelper(0x2d, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

void CMSChart::SetDoSetCursor(BOOL bNewValue)
{
static BYTE parms[] =
VTS_BOOL;
InvokeHelper(0x2d, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
bNewValue);
}

BOOL CMSChart::GetChart3d()
{
BOOL result;
InvokeHelper(0x2f, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
return result;
}

VARIANT CMSChart::GetChartData()
{
VARIANT result;
InvokeHelper(0x0, DISPATCH_PROPERTYGET, VT_VARIANT, (void*)&result, NULL);
return result;
}

void CMSChart::SetChartData(const VARIANT& newValue)
{
static BYTE parms[] =
VTS_VARIANT;
InvokeHelper(0x0, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
&newValue);
}

long CMSChart::GetMousePointer()
{
long result;
InvokeHelper(0x4a, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetMousePointer(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x4a, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

void CMSChart::Refresh()
{
InvokeHelper(DISPID_REFRESH, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

void CMSChart::EditPaste()
{
InvokeHelper(0x31, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

void CMSChart::EditCopy()
{
InvokeHelper(0x32, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

void CMSChart::Layout()
{
InvokeHelper(0x34, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

void CMSChart::ToDefaults()
{
InvokeHelper(0x35, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

void CMSChart::SelectPart(short part, short index1, short index2, short index3, short index4)
{
static BYTE parms[] =
VTS_I2 VTS_I2 VTS_I2 VTS_I2 VTS_I2;
InvokeHelper(0x38, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
part, index1, index2, index3, index4);
}

void CMSChart::GetSelectedPart(short* part, short* index1, short* index2, short* index3, short* index4)
{
static BYTE parms[] =
VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2;
InvokeHelper(0x39, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
part, index1, index2, index3, index4);
}

void CMSChart::TwipsToChartPart(long xVal, long yVal, short* part, short* index1, short* index2, short* index3, short* index4)
{
static BYTE parms[] =
VTS_I4 VTS_I4 VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2 VTS_PI2;
InvokeHelper(0x3b, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
xVal, yVal, part, index1, index2, index3, index4);
}

long CMSChart::GetOLEDragMode()
{
long result;
InvokeHelper(0x60e, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetOLEDragMode(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x60e, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

long CMSChart::GetOLEDropMode()
{
long result;
InvokeHelper(0x60f, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
return result;
}

void CMSChart::SetOLEDropMode(long nNewValue)
{
static BYTE parms[] =
VTS_I4;
InvokeHelper(0x60f, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
nNewValue);
}

void CMSChart::OLEDrag()
{
InvokeHelper(0x610, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

LPUNKNOWN CMSChart::GetDataSource()
{
LPUNKNOWN result;
InvokeHelper(0x47, DISPATCH_PROPERTYGET, VT_UNKNOWN, (void*)&result, NULL);
return result;
}

void CMSChart::SetRefDataSource(LPUNKNOWN newValue)
{
static BYTE parms[] =
VTS_UNKNOWN;
InvokeHelper(0x47, DISPATCH_PROPERTYPUTREF, VT_EMPTY, NULL, parms,
newValue);
}

CString CMSChart::GetDataMember()
{
CString result;
InvokeHelper(0x4b, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
return result;
}

void CMSChart::SetDataMember(LPCTSTR lpszNewValue)
{
static BYTE parms[] =
VTS_BSTR;
InvokeHelper(0x4b, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
lpszNewValue);
}
</span>
创建对话框如下:

MsChart控件在VC++中的使用

首先声明变量并msChart控件 添加控件变量CMSChart m_Chart;,并初始化

<span style="font-family:KaiTi_GB2312;font-size:18px;">void CChartDemoDlg::InitChart()
{
//设置标题
m_Chart.SetTitleText(LPCTSTR("实时曲线图"));//Title 为CString类型
//设置栈模式
m_Chart.SetStacking(FALSE);
//设置行数及列数
m_Chart.SetRowCount(1);//iRowCount和iColumnCount为int型
m_Chart.SetColumnCount(1);
m_Chart.SetRow(1);
m_Chart.SetRowLabel("");
m_Chart.GetDataGrid().SetData(1, 1, 0, 0);
//设置x轴及y轴的标题。xTitle和yTitle为CString型
VARIANT var;
m_Chart.GetPlot().GetAxis(0,var).GetAxisTitle().SetText("Time"); //x轴
m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("DataValue"); //y轴
//设置控件类型
m_Chart.SetChartType(3);//3:曲线型;1:条形;14:饼图
//设置背景颜色
m_Chart.GetBackdrop().GetFill().SetStyle(1);
m_Chart.GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);

//设置数据系列的颜色:如果是曲线图则对应每条曲线的颜色
for (int i = 1; i <= m_Chart.GetColumnCount(); i++ )
{//这里设置为随机颜色
m_Chart.GetPlot().GetSeriesCollection().GetItem(i).GetPen().GetVtColor().Set(rand() * 230 / RAND_MAX, rand() * 230 / RAND_MAX, rand() * 230 / RAND_MAX);
m_Chart.GetPlot().GetSeriesCollection().GetItem(i).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
}
//设置x轴的其他属性
m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE); // 不自动标注X轴刻度
m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(1);// 每刻度一个标注
m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(1); // 每刻度一个刻度线

//不自动标注y轴
m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(FALSE);
m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(100); // y轴最大刻度为100
m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0); // y轴最小刻度为0
m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(5); // 将y轴刻度5等分
m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1); // 每刻度一个刻度线
// m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("YourTitle"); // y的轴名称

//不要与x轴垂直的表格线
m_Chart.GetPlot().GetAxis(0,var).GetAxisGrid().GetMajorPen().SetStyle(0);// no x grids
//隐藏第二y轴,即右边的y轴
m_Chart.GetPlot().GetAxis(2,var).GetAxisScale().SetHide(TRUE);
//刷新控件
m_Chart.Refresh();
}</span>
画图按钮的消息响应函数:
<span style="font-family:KaiTi_GB2312;font-size:18px;">void CChartDemoDlg::OnButDraw() 
{
// TODO: Add your control notification handler code here
SetTimer(100, 100, NULL);//1/10 second
GetDlgItem(IDC_BUT_DRAW)->EnableWindow(FALSE);//
}</span>
定时器函数
<span style="font-family:KaiTi_GB2312;font-size:18px;">void CChartDemoDlg::OnTimer(UINT nIDEvent) 
{
int nYValue = rand()%100;
nCount++;
CString str;
int i;
i = nCount;
str.Format("%d", i);
int inPos = m_Chart.GetRowCount() + 1;
m_Chart.GetDataGrid().InsertRows(inPos, 1);
m_Chart.SetRow(inPos);
m_Chart.SetRowLabel(str);//sLabel??CString??
m_Chart.GetDataGrid().SetData(inPos, 1, nYValue, 0);
if (nCount > 30)
{
m_Chart.GetDataGrid().DeleteRows(inPos - 30, 1);
}
m_Chart.Refresh();
//每产生30个数据便停止计时并启用start按钮,再点击一下即可以继续产生下30个数据
if (nCount % 30 == 0)
{
KillTimer(100);
GetDlgItem(IDC_BUT_DRAW)->EnableWindow(TRUE);//
}

CDialog::OnTimer(nIDEvent);
}
</span>

MsChart控件在VC++中的使用MsChart控件在VC++中的使用

折线图,柱状图,饼图的相互转化

以下代码可将折线图,柱状图转化为饼状图:

<span style="font-family:KaiTi_GB2312;font-size:18px;">m_Chart.SetChartType(14); //转化为饼状图</span>
<span style="font-family:KaiTi_GB2312;font-size:18px;">m_Chart.SetChartType(1); //转化为柱状图</span>
<span style="font-family:KaiTi_GB2312;font-size:18px;">m_Chart.SetChartType(3); //转化为曲线图</span>
<span style="font-family:KaiTi_GB2312;font-size:18px;">