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

📄 ch9demo8view.cpp

📁 零基础学Visual.C....教案PPT.随书光盘-452M.zip
💻 CPP
字号:
// Ch9Demo8View.cpp : implementation of the CCh9Demo8View class
//

#include "stdafx.h"
#include "Ch9Demo8.h"
#include <math.h>
#include "Ch9Demo8Doc.h"
#include "Ch9Demo8View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo8View

IMPLEMENT_DYNCREATE(CCh9Demo8View, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo8View construction/destruction

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

}

CCh9Demo8View::~CCh9Demo8View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo8View drawing

void CCh9Demo8View::OnDraw(CDC* pDC)
{
	CCh9Demo8Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	// 设置映射模式为 MM_ANISOTROPIC
	pDC->SetMapMode(MM_ANISOTROPIC);
	//设置窗口左上角的坐标(-4pie,2),放大1000倍,下同
	pDC->SetWindowOrg(int(-4000*3.14), 2000);
	// 设置窗口度量
	pDC->SetWindowExt(int(8000*3.14), -4000);
	// 获得客户区矩形
	CRect rc;
	GetClientRect(rc);
	// 设置视口左上角的坐标
	pDC->SetViewportOrg(0, 0);
	// 设置视口度量
	pDC->SetViewportExt(rc.Width(), rc.Height());
	// 创建蓝色实线画笔
	CPen pen(PS_SOLID,1,RGB(0, 0, 255)),pen1(PS_DASH, 1, RGB(128,0, 0)), *pOldPen;
	pOldPen=pDC->SelectObject(&pen);//载入蓝色实线画笔
	pDC->MoveTo(int(-4000*3.14), 0);
	for (double x=(-4*3.14);x<=0; x+=0.01)//绘制负半轴正弦曲线
	{
		pDC->LineTo(int(1000*x),int(1000*sin(x)));
	}

	for (x=0; x<=4*3.14; x+=0.01)//绘制正半轴正弦曲线
	{
		pDC->LineTo(int(1000*x), int(1000*sin(x)));
	}
	pDC->SelectObject(&pen1);//载入虚线画笔
	pDC->MoveTo(int(-4000*3.14),0);//绘制X轴
	pDC->LineTo(int(4000*3.14), 0);
	pDC->MoveTo(0, -2000);//绘制Y轴
	pDC->LineTo(0, 2000);
	// 恢复设备上下文原有的画笔
	pDC->SelectObject(pOldPen);
	pen.DeleteObject();
	pen1.DeleteObject();
}

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo8View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo8View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo8View message handlers

⌨️ 快捷键说明

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