day10view.cpp

来自「学习VC的一些例子」· C++ 代码 · 共 181 行

CPP
181
字号
// Day10View.cpp : implementation of the CDay10View class
//

#include "stdafx.h"
#include "Day10.h"

#include "Line.h"
#include "Day10Doc.h"
#include "Day10View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDay10View

IMPLEMENT_DYNCREATE(CDay10View, CView)

BEGIN_MESSAGE_MAP(CDay10View, CView)
	//{{AFX_MSG_MAP(CDay10View)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CDay10View construction/destruction

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

}

CDay10View::~CDay10View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDay10View drawing

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

	// Get the number of lines in the document
	int liCount = pDoc->GetLineCount();
	
	// Are there any lines in the document
	if (liCount)
	{
		int liPos;
		CLine *lptLine;
		// Loopthrough the lines in the document
		for (liPos = 0; liPos < liCount; liPos++)
		{
			// Get the from and to point for each line
			lptLine = pDoc->GetLine(liPos);
			
			// Draw the line
			lptLine->Draw(pDC);
		}
	}
}


/////////////////////////////////////////////////////////////////////////////
// CDay10View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDay10View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDay10View message handlers

void CDay10View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	// Capture the mouse, so no other application can
	// grab it if the mouse leaves the window area
	SetCapture();
	
	// Save the point
	m_ptPrevP = point;

	CView::OnLButtonDown(nFlags, point);
}

void CDay10View::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	// Have we captured the mouse?
	if (GetCapture() == this)
		// If so, release it so other applications can
		// have it
		ReleaseCapture();

	CView::OnLButtonUp(nFlags, point);
}

void CDay10View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	// check to see if the left mouse button iS down
	if ((nFlags & MK_LBUTTON) == MK_LBUTTON)
	{
		// Have we captured the mouse?
		if (GetCapture() == this)
		{
			// Get the Device Context
			CClientDC dc(this);
			
			// Add the line to the document
			CLine *pLine = GetDocument()->AddLine(m_ptPrevP, point);
			
			// Draw the cunrent stretch of line
			pLine->Draw(&dc);
			
			// Save the curnent point as the pnevious point
			m_ptPrevP = point;
		}
	}
	
	CView::OnMouseMove(nFlags, point);
}

⌨️ 快捷键说明

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