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

📄 myview.cpp

📁 VC面向对象的学习教程
💻 CPP
字号:
// MyView.cpp : implementation of the CMyView class
//

#include "stdafx.h"
#include "My.h"

#include "MyDoc.h"
#include "MyView.h"

#include "Math.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

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

}

CMyView::~CMyView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyView drawing

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

	//在极坐标下画R=2*theta曲线(阿基米德螺线)
	const double PI = 3.14159265359;
	const double dbYMax = 14.0;
	const double dbYMin = -14.0;
	const double dbXMin = -14.0;
	const double dbXMax = 14.0;
	const int iPt = 180;

	const int xOrg = 200;
	const int yOrg = 190;
	const int xMin = 50;
	const int yMax = 350;
	const int xMax = 700;
	const int yMin = 20;

	//换算数据并画出折线
	double dbXRatio = (xMax-xMin)/(dbXMax-dbXMin);
	double dbYRatio = (yMax-yMin)/(dbYMax-dbYMin);
	
	double dbRatio = dbXRatio > dbYRatio ? dbYRatio : dbXRatio;

	//画轴
	//同心圆	
	int iInc = (int) (dbRatio * (dbXMax - dbXMin)/8.0); //半径的增量
	for(int i = 4; i>0; --i)
	{
		CRect rectScale;
		rectScale.bottom = yOrg + iInc * i;
		rectScale.left = xOrg - iInc * i;
		rectScale.right = xOrg + iInc * i;
		rectScale.top = yOrg - iInc * i;
		pDC->Ellipse(rectScale);
	}
	//角度轴
	int iR = iInc * 4;   //最外圈圆的半径
	for (i = -45; i<=90; i+=45)
	{
		pDC->MoveTo((int) (iR * cos(i*PI/180.0) + xOrg), 
						(int) (yOrg - iR * sin(i*PI/180.0)));
		pDC->LineTo((int) (iR * cos((i+180)*PI/180.0) + xOrg), 
						(int) (yOrg - iR * sin((i+180)*PI/180.0)));
	}
	//画折线
	int x = xOrg;
	int y = yOrg;
	pDC->MoveTo(x,y);
	
	for(i=0; i<=iPt; i++)
	{
		double dbTheta =i*2.0/180*PI;
		double dbX = 2*dbTheta*cos(dbTheta);
		double dbY = 2*dbTheta*sin(dbTheta);

		x = (int) (dbRatio * dbX + xOrg);
		y = (int) (yOrg - dbRatio * dbY);
		pDC->LineTo(x,y);

	}


}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

⌨️ 快捷键说明

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