day11doc.cpp

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

CPP
142
字号
// Day11Doc.cpp : implementation of the CDay11Doc class
//

#include "stdafx.h"
#include "Day11.h"

#include "Line.h"
#include "Day11Doc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDay11Doc

IMPLEMENT_DYNCREATE(CDay11Doc, CDocument)

BEGIN_MESSAGE_MAP(CDay11Doc, CDocument)
	//{{AFX_MSG_MAP(CDay11Doc)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CDay11Doc construction/destruction

const COLORREF CDay11Doc::m_crColor[8] =
{
	RGB(  0,   0,   0),
	RGB(  0,   0, 255),
	RGB(  0, 255,   0),
	RGB(  0, 255, 255),
	RGB(255,   0,   0),
	RGB(255,   0, 255),
	RGB(255, 255,   0),
	RGB(255, 255, 255)
};


CDay11Doc::CDay11Doc()
{
	// TODO: add one-time construction code here

CDay11Doc::~CDay11Doc()
{

}
}

BOOL CDay11Doc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CDay11Doc serialization

void CDay11Doc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CDay11Doc diagnostics

#ifdef _DEBUG
void CDay11Doc::AssertValid() const
{
	CDocument::AssertValid();
}

void CDay11Doc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDay11Doc commands


CLine * CDay11Doc::AddLine(CPoint ptFrom, CPoint ptTo)
{
	static UINT nWidth[5] = {1, 8, 16, 24, 32};

	// Create a new CLine object
	CLine *pLine = new CLine(ptFrom, ptTo, m_crColor[m_nColor], nWidth[m_nWidth]);
	
	try
	{
		// Add the new line to the object annay
		m_oaLines.Add(pLine);
		// Mark the document as dirty
		SetModifiedFlag();
	}

	// Did we run into a memory exception?
	catch (CMemoryException* perr)
	{
		// Display a message fon the user, giving him or her the
		// bad news
		AfxMessageBox("out of memory", MB_ICONSTOP | MB_OK);
		
		// Did we create a line object
		if (pLine)
		{
			// Delete it
			delete pLine;
			pLine = NULL;
		}
		
		// Delete the exception object
		perr->Delete();
	}
	
	return pLine;
}

CLine* CDay11Doc::GetLine(int nIndex)
{
	return (CLine *) m_oaLines[nIndex];
}

⌨️ 快捷键说明

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