![]() |
#2
lchh040502112012-07-02 16:33
|
只有本站会员才能查看附件,请 登录
我建立了一个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_)
//
/////////////////////////////////////////////////////////////////////////////
#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;
}
{
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;
}
}
{
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;
}
{
// 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 编辑 ]