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

📄 ch9demo3view.cpp

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

#include "stdafx.h"
#include "Ch9Demo3.h"

#include "Ch9Demo3Doc.h"
#include "Ch9Demo3View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo3View

IMPLEMENT_DYNCREATE(CCh9Demo3View, CView)

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo3View construction/destruction

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

}

CCh9Demo3View::~CCh9Demo3View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo3View drawing

void CCh9Demo3View::OnDraw(CDC* pDC)
{
	CCh9Demo3Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CPen pen[5];
	//创建实线画笔
	pen[0].CreatePen(PS_SOLID, 5, RGB(255, 0, 0));
	//创建虚线画笔
	pen[1].CreatePen(PS_DASH, 1, RGB(0, 255, 0));
	//创建点线画笔
	pen[2].CreatePen(PS_DOT, 1, RGB(0, 0, 255));
	//创建点划线画笔
	pen[3].CreatePen(PS_DASHDOT, 1, RGB(0, 255, 255));
	// 创建双点划线画笔
	pen[4].CreatePen(PS_DASHDOTDOT, 1, RGB(255, 0, 255));

	// 保存指向设备上下文原有画笔的指针
	CPen *pOldPen;
	//以实线画笔绘制矩形
	pOldPen=pDC->SelectObject(&pen[0]);
	pDC->Rectangle(10, 10, 110, 110);
	pDC->TextOut(10, 115, "Rectangle绘制矩形");

	//使用虚线画笔和函数Polyline输出多段折线
	pDC->SelectObject(&pen[1]);//载入画笔
	pDC->Rectangle(180, 10, 330, 110);//绘制矩形
	CPoint pts[]={CPoint(190, 20), CPoint(200, 60), CPoint(270, 40), CPoint(210, 80), 
	CPoint(250, 100), CPoint(300, 30), CPoint(310, 80)};
	pDC->Polyline(pts, 7);//绘制多端折线
	pDC->TextOut(180, 115, "Polyline绘制多段折线");

	// 使用Pie和Arc输出饼图和弧形
	pDC->SelectObject(&pen[2]);//载入点线画笔
	pDC->Ellipse(10, 140, 160, 240);
	pDC->SelectObject(&pen[3]);//载入点划线画笔
	pDC->Pie(20, 150, 150, 230, 160, 160, 10, 160);
	pDC->SelectObject(&pen[4]);//载入双点划线画笔
	pDC->Arc(20, 150, 150, 230, 10, 220, 160, 220);
	pDC->TextOut(10, 245, "不同画笔绘制椭圆、弧形和饼图");
	//恢复设备上下文的原有画笔
	pDC->SelectObject(pOldPen);
	//删除所创建的画笔资源
	for (int i=0; i<5; i++)
	pen[i].DeleteObject();
}

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo3View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo3View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCh9Demo3View message handlers

⌨️ 快捷键说明

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