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

📄 curveview.cpp

📁 如何使用MATLAB编程
💻 CPP
字号:
// CurveView.cpp : implementation file
//

#include "stdafx.h"
#include "lag.h"
#include "CurveView.h"
#include "AddDataDlg.h"
#include "Lagrange.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCurveView

IMPLEMENT_DYNCREATE(CCurveView, CFormView)

CCurveView::CCurveView()
	: CFormView(CCurveView::IDD)
{
	//{{AFX_DATA_INIT(CCurveView)
	//}}AFX_DATA_INIT
	m_show = FALSE;
}

CCurveView::~CCurveView()
{
}

void CCurveView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCurveView)
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CCurveView, CFormView)
	//{{AFX_MSG_MAP(CCurveView)
	ON_BN_CLICKED(IDC_ADDNUMBER, OnAddnumber)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_WM_PAINT()
	ON_WM_CANCELMODE()
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CCurveView diagnostics

#ifdef _DEBUG
void CCurveView::AssertValid() const
{
	CFormView::AssertValid();
}

void CCurveView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CCurveView message handlers

void CCurveView::OnAddnumber() 
{
	// TODO: Add your control notification handler code here
	m_show = FALSE;
	CAddDataDlg dlg;
	m_DataArr.RemoveAll();
	dlg.SetArr(&m_DataArr);
	dlg.DoModal();
}

void CCurveView::OnButton2() 
{
	// TODO: Add your control notification handler code here
	CLagrange lag;	
	int i;
	double delt;
	int n = 100;
	func d;

	lag.SetArray(&m_DataArr);
	m_Data.RemoveAll();
	
	double minx,maxx;
	
	for (i = 0,minx = 999999999,maxx = -999999999; i < m_DataArr.GetSize(); i ++)
	{
		if (minx > m_DataArr.GetAt(i).x)
		{
			minx = m_DataArr.GetAt(i).x;
		}
		if (maxx < m_DataArr.GetAt(i).x)
		{
			maxx = m_DataArr.GetAt(i).x;
		}
	}
	
	delt = (maxx-minx)/n;
	for (;minx <= maxx + 0.5; minx += delt)
	{
		d.x = minx;
		lag.SetX(minx);
		d.y = lag.Compute();
		m_Data.Add(d);
	}
	
	m_show = TRUE;
	ShowCurve();
}

void CCurveView::ShowCurve()
{
	CRect rc;
	GetClientRect(&rc);
	CClientDC dc(this);
	CPoint centpoint;
	centpoint.x = (rc.right+rc.left)/2;
	centpoint.y = (rc.bottom+rc.top)/2;
	if (m_show)
	{
		dc.FillSolidRect(0,0,rc.Width(),rc.Height()-200,RGB(236,233,216));//RGB(214,210,205)RGB(236,233,216)	
		dc.MoveTo((int)(centpoint.x+m_Data.GetAt(0).x),(int)(centpoint.y-m_Data.GetAt(0).y));
		for (int i=0; i<m_Data.GetSize(); i++ )
		{			
			dc.LineTo((int)(centpoint.x+m_Data.GetAt(i).x),(int)(centpoint.y-m_Data.GetAt(i).y));
			dc.SetPixel((int)(centpoint.x+m_Data.GetAt(i).x),(int)(centpoint.y-m_Data.GetAt(i).y),RGB(0,0,255));
			//dc.TextOut(centpoint.x+m_Data.GetAt(i).x,centpoint.y-m_Data.GetAt(i).y,"*");
		}
		for (int j=0; j<m_DataArr.GetSize(); j++)
		{
			dc.SetPixel((int)(centpoint.x+m_DataArr.GetAt(j).x),(int)(centpoint.y-m_DataArr.GetAt(j).y),RGB(250,0,0));
			dc.TextOut((int)(centpoint.x+m_DataArr.GetAt(j).x),(int)(centpoint.y-m_DataArr.GetAt(j).y),"*");
		}
	}
}

void CCurveView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	ShowCurve();
}

HBRUSH CCurveView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	//236,233,216
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

⌨️ 快捷键说明

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