⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testchartview.cpp

📁 用VC写的一个将串口数据用图形曲线的形式显示出来。这是一个项目中的一部分。
💻 CPP
字号:
// TestChartView.cpp : implementation of the CTestChartView class
//

#include "stdafx.h"
#include "TestChart.h"

#include "TestChartDoc.h"
#include "TestChartView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern double g_van;
/////////////////////////////////////////////////////////////////////////////
// CTestChartView

IMPLEMENT_DYNCREATE(CTestChartView, CView)

BEGIN_MESSAGE_MAP(CTestChartView, CView)
	//{{AFX_MSG_MAP(CTestChartView)
	ON_WM_TIMER()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestChartView construction/destruction

CTestChartView::CTestChartView()
{
	// TODO: add construction code here
	m_pView=this;
}

CTestChartView::~CTestChartView()
{
}

BOOL CTestChartView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestChartView drawing

void CTestChartView::OnDraw(CDC* pDC)
{
	CTestChartDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
//	OnInitialUpdate();
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CTestChartView printing

BOOL CTestChartView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTestChartView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTestChartView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTestChartView diagnostics

#ifdef _DEBUG
void CTestChartView::AssertValid() const
{
	CView::AssertValid();
}

void CTestChartView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CTestChartDoc* CTestChartView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestChartDoc)));
	return (CTestChartDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestChartView message handlers

void CTestChartView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	CRect rect;
	GetClientRect(&rect);
	rect.bottom=rect.bottom;
	m_wndChart.Create(NULL,
                  NULL,
                  WS_CHILD|WS_VISIBLE,
                  rect,
                  this,
                  1);
	m_wndChart.SetChartType(TYPE_STRIP_CHART_30);

	DWORD dwAxisStyleX(eAUTO_SCALE|m_wndChart.GetAxisStyleX());
    m_wndChart.SetAxisStyleX(dwAxisStyleX);
    m_wndChart.SetAxisStyleY(eAUTO_SCALE|m_wndChart.GetAxisStyleY());

    m_wndChart.SetAxisFormatString(X_AXIS, CString("%.2f"));
    m_wndChart.SetAxisFormatString(Y_AXIS, CString("%.2f"));

    m_wndChart.ShowHeader(FALSE);
    m_wndChart.ShowFooter(FALSE);
    m_wndChart.ShowLegend(FALSE);

    m_wndChart.Invalidate();
    m_wndChart.UpdateWindow();

	m_wndChart.Purge();
	m_wndChart.AddDataSeries("RED", RGB(255, 0, 0));
	
	OnStartTimer();
	
}

void CTestChartView::OnTimer(UINT nIDEvent) 
{
	CTime TTime=CTime::GetCurrentTime();
	if(1==nIDEvent)
	{
		SetTimer(3,5000,NULL);
		KillTimer(1);
	}
    if(nIDEvent==3) 
	{
        DataPoint.m_dX = TTime.GetTime();
		DataPoint.m_dY=g_van;
         DataPoint.m_crColor = RGB(rand()%255, rand()%255, rand()%255);
        if (DataPoint.m_dY>1.7)
            DataPoint.m_hIcon = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_ICON3));
        m_wndChart.AddDataPoint(&DataPoint);
      
        m_wndChart.UpdateWindow();
	
	}
        
    CView::OnTimer(nIDEvent);
    
    return;
}


void CTestChartView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CView::OnPaint() for painting messages
}



void CTestChartView::OnStartTimer()
{
	SetTimer(1,100,NULL);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -