// TestChartWndInMFCView.cpp : implementation of the CTestChartWndInMFCView class
//

#include "stdafx.h"
#include "TestChartWndInMFC.h"

#include "TestChartWndInMFCDoc.h"
#include "TestChartWndInMFCView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestChartWndInMFCView

IMPLEMENT_DYNCREATE(CTestChartWndInMFCView, CView)

BEGIN_MESSAGE_MAP(CTestChartWndInMFCView, CView)
	//{{AFX_MSG_MAP(CTestChartWndInMFCView)
	ON_WM_CREATE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CTestChartWndInMFCView construction/destruction

CTestChartWndInMFCView::CTestChartWndInMFCView()
{
	// TODO: add construction code here

}

CTestChartWndInMFCView::~CTestChartWndInMFCView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestChartWndInMFCView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CTestChartWndInMFCView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTestChartWndInMFCView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CTestChartWndInMFCView message handlers

int CTestChartWndInMFCView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	double *pX, *pY;
	int i;
	
	RECT rt;
	rt.left = rt.top = 0;
	rt.right = rt.bottom = 500;
	//if(m_ChartWnd.Attach(m_hWnd, kTypeXY))
	if(m_ChartWnd.Attach(m_hWnd, kTypeXY, rt))
	{
		pX=new double[200];
		pY=new double[200];
		for(i=0; i<200; i++)
		{
			pX[i]=(i-100.0)/100.0;
			pY[i]=pX[i]*pX[i];
		}
		m_ChartWnd.GetChart()->AddCurve(pX, pY, 200);
		delete []pY;
		delete []pX;
		m_ChartWnd.GetChart()->SetTitle(_TEXT("Testing PlotWnd"));
		m_ChartWnd.GetChart()->SetBkgndColor(RGB(160,192,192));
	}
	
	return 0;
}
