grview.cpp

来自「windows ce开发技巧与实例光盘代码」· C++ 代码 · 共 194 行

CPP
194
字号
// GrView.cpp : implementation of the CGrView class
//

#include "stdafx.h"
#include "Gr.h"

#include "GrDoc.h"
#include "GrView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGrView

IMPLEMENT_DYNCREATE(CGrView, CScrollView)

BEGIN_MESSAGE_MAP(CGrView, CScrollView)
	//{{AFX_MSG_MAP(CGrView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGrView construction/destruction

CGrView::CGrView()
{
	// TODO: add construction code here
	pie =NULL;
}

CGrView::~CGrView()
{
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGrView drawing

void CGrView::OnDraw(CDC* pDC)
{
	CGrDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	
//	pDC->MoveTo(50,50);
//	pDC->LineTo(pDoc->Gr.GetX(),pDoc->Gr.GetY());
//	Graph->DrawLine(pDC,50,50,pDoc->Gr.GetX(),pDoc->Gr.GetY(),5,RGB(255,255,0));
//	DrawRangle(pDC,0);
//	Graph->DrawRectangle(pDC,50,50,pDoc->Gr.GetX(),pDoc->Gr.GetY());
//	Graph = new CBar();
//	double AngS2 = 0*PI/180;
//	double AngE2 = 360*PI/180;
//	Graph->DrawArc(pDC,85,95,80,AngS2,AngE2,1,RGB(0,0,0),RGB(0,0,30));
//	double AngS = 0*PI/180;
//	double AngE = 60*PI/180;
//	Graph->DrawArc(pDC,90,90,80,AngS,AngE,1,RGB(0,0,0),RGB(255,0,0));
//	double AngS1 = 60*PI/180;
//	double AngE1 = 100*PI/180;
//	Graph->DrawArc(pDC,90,90,80,AngS1,AngE1,1,RGB(0,0,0),RGB(0,255,0));
//	AngS1 = 100*PI/180;
//	AngE1 = 180*PI/180;
//	Graph->DrawArc(pDC,90,90,80,AngS1,AngE1,1,RGB(0,0,0),RGB(0,255,255));
//	AngS1 = 180*PI/180;
//	AngE1 = 360*PI/180;
//	Graph->DrawArc(pDC,90,90,80,AngS1,AngE1,1,RGB(0,0,0),RGB(255,255,0));

//	Graph->DrawColumn(pDC,150,90,150+60,90+20,50,1,RGB(0,0,0),RGB(255,255,0));
//	Graph->DrawCub(pDC,100,180,150,180,100,1,RGB(0,0,0),RGB(255,0,255));
//	Graph->DrawPoint(pDC,200,200);
//	Graph->DrawPoint(pDC,180,180,CBaseGr::XCROSS,5,1,RGB(255,0,0),RGB(0,255,0));
/*	Graph->SetYMin(25);
	Graph->SetYMax(100);
	Graph->SetYName(_T("纵坐标"));
	Graph->SetXName(_T("横坐标"));
	Graph->SetTitle(_T("五个柱状图"));
	Graph->SetLegend(_T("一月"),35,RGB(255,0,0));
	Graph->SetLegend(_T("二月"),55,RGB(255,255,0));
	Graph->SetLegend(_T("三月"),100,RGB(0,255,0));
	Graph->SetLegend(_T("四月"),60,RGB(0,255,255));
	Graph->SetLegend(_T("五月"),60,RGB(0,0,255));
	//Graph->DrawCoordinate(pDC,40,40,200,220,TRUE);
	Graph->Set3DBar(TRUE);
//	Graph->SetWithDash(TRUE);
	Graph->Set3DMode(TRUE);
	Graph->DrawBar(pDC,0,0,240,280);
//	Graph->DrawXCoordinate(pDC,40,40,200,220);
//	Graph->DrawTitle(pDC,40,40,200,220,CBaseGr::BOTTOM);
//	Graph->DrawLegend(pDC,202,40,30,CBaseGr::TOP);

	delete Graph;
	*/
//	pie = new CPie();
//	pie->SetCutPie(TRUE);
//	pie->SetTitle(_T("饼图"));
//	pie->SetLegend(_T("一月"),35,RGB(255,0,0));
//	pie->SetLegend(_T("二月"),55,RGB(255,255,0));
//	pie->SetLegend(_T("三月"),100,RGB(0,255,0));
//	pie->SetLegend(_T("四月"),60,RGB(0,255,255));
//	pie->SetLegend(_T("五月"),60,RGB(0,0,255));
//	pie->SetWithText(TRUE);
//	pie->DrawPie(pDC,0,0,240,280);
//	delete pie;
//	pie = NULL;
	line = new CLine();
	line->SetTitle(_T("曲线图"));
	line->SetYName(_T("纵坐标"));
	line->SetXName(_T("横坐标"));
	line->SetYMin(0);
	line->SetYMax(100);
	line->SetXMin(0);
	line->SetXMax(100);
	line->SetWithDash(TRUE);
	CLineData* ld1 = new CLineData();
	ld1->SetLegend(_T("一月"));
	ld1->SetPointType(CBaseGr::CIRCLE);
	ld1->SetLineColor(RGB(255,0,0));
	ld1->SetPointColor(RGB(255,0,0));
	ld1->AddData(10,10);
	ld1->AddData(20,20);
	ld1->AddData(30,40);
	ld1->AddData(40,40);
	ld1->AddData(50,60);
	ld1->AddData(60,60);
	line->AddLineData(ld1);
	CLineData* ld2 = new CLineData();
	ld2->SetLegend(_T("二月"));
	ld2->SetPointType(CBaseGr::FDIAMOND);
	ld2->SetLineColor(RGB(0,255,0));
	ld2->SetPointColor(RGB(0,255,0));
	ld2->AddData(10,30);
	ld2->AddData(25,20);
	ld2->AddData(35,40);
	ld2->AddData(40,50);
	ld2->AddData(50,65);
	ld2->AddData(60,70);
	line->AddLineData(ld2);
//	line->SetWithDot(FALSE);
	line->SetDotSize(3);
	line->SetWithDash(FALSE);
	line->DrawCurveLine(pDC,0,0,240,280);
	delete line;
	delete ld1;
	delete ld2;
	
}

void CGrView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CGrView diagnostics

#ifdef _DEBUG
void CGrView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CGrView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CGrView message handlers



⌨️ 快捷键说明

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