在View中使用PlotLab
最近一直在钻研PlotLab_VC库,发现PlotLab_VC帮助文档里只给出了如何在对话框里使用PlotLab的例程,没有在View中使用的例子,今晚试了一些,终于在View下试验成功了。先上图看看。 我建立了一个SDI工程,名为Test。
第一步,在TestView.h中该如下代码
程序代码:// TestView.h : interface of the CTestView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_TESTVIEW_H__63DC1CE4_B0BF_4911_B9F3_1644DD0D5E10__INCLUDED_)
#define AFX_TESTVIEW_H__63DC1CE4_B0BF_4911_B9F3_1644DD0D5E10__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <CSLScope.h>//////////////添加的代码
class CTestView : public CView
{
protected: // create from serialization only
CTestView();
DECLARE_DYNCREATE(CTestView)
// Attributes
public:
CTestDoc* GetDocument();
// Operations
public:
CTSLScope scope;/////////添加的代码
bool bScopeCreated;//////////添加的代码
int counter;/////////////添加的代码
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTestView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnInitialUpdate();
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CTestView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CTestView)
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnDatadraw();
afx_msg void OnDataclear();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
#ifndef _DEBUG // debug version in TestView.cpp
inline CTestDoc* CTestView::GetDocument()
{ return (CTestDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_TESTVIEW_H__63DC1CE4_B0BF_4911_B9F3_1644DD0D5E10__INCLUDED_) 第二步,初始化,重写OnInitialUpdate()
程序代码:void CTestView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
//VCL_InitControls(AfxGetApp()->m_pMainWnd->GetSafeHwnd());
VCL_InitControls(this->GetSafeHwnd());
scope.Open(this->GetSafeHwnd());
scope.Title.Text="";//设置示波器标题
scope.XAxis.AxisLabel.Text="采样点";//设置坐标轴标签
scope.YAxis.AxisLabel.Text="幅度";
scope.Color=RGB(0,0,20);//设置背景颜色
scope.Channels.Add();//添加通道
scope.Channels[0].Name="通道一";
scope.Channels[1].Name="通道二";
VCL_Loaded();
bScopeCreated=true;
counter=0;
} 第三步,响应WM_SIZE消息
程序代码:void CTestView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(bScopeCreated)
{
scope.Width=cx;
scope.Height=cy;
}
} 第四步,绘制数据,在菜中添加数据|绘制和清除菜单,分别添加响应函数
程序代码:void CTestView::OnDatadraw()//绘制数据曲线
{
// TODO: Add your command handler code here
float SampleDatas[1000];
for (int i=0;i<1000;i++)
{
SampleDatas[i]=rand()-1000;
}
scope.Channels[0].Data.SetYData(SampleDatas,1000);
for(i=0;i<1000;i++)
{
SampleDatas[i]=(float)(counter++%120)*300-1000;
}
scope.Channels[1].Data.SetYData(SampleDatas,1000);
}
void CTestView::OnDataclear() //清除数据曲线
{
// TODO: Add your command handler code here
scope.Channels[0].Data.Clear();
scope.Channels[1].Data.Clear();
scope.Hold=false;
} 最后奉上源代码,共同学习,共同进步
[ 本帖最后由 hlmzrdongdong 于 2012-5-14 21:42 编辑 ]








还其它有资料吗。这个控件太难弄了
收了,谢谢