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

📄 paintdoc.cpp

📁 这是一个小型画板系统
💻 CPP
字号:
// paintDoc.cpp : implementation of the CPaintDoc class
//

#include "stdafx.h"
#include "paint.h"

#include "paintDoc.h"
#include "Line.h"
#include "Rectangle.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPaintDoc

IMPLEMENT_DYNCREATE(CPaintDoc, CDocument)

BEGIN_MESSAGE_MAP(CPaintDoc, CDocument)
	//{{AFX_MSG_MAP(CPaintDoc)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPaintDoc construction/destruction

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

}

CPaintDoc::~CPaintDoc()
{
}

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

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

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CPaintDoc serialization

void CPaintDoc::Serialize(CArchive& ar)
{
	int count;
	int index;	
	if (ar.IsStoring())
	{
		// TODO: add storing code here

		count =m_obLineArray.GetSize();
		ar<<count;
		for(index=0;index<count;index++)
		{
			ar<<(CLine *)m_obLineArray.GetAt(index);
		}

		count = m_obRectArray.GetSize();
		ar<<count;
		for(index=0;index<count;index++)
		{
			ar<<(CRectangle *)m_obRectArray.GetAt(index);			
		}
	}
	else
	{
		// TODO: add loading code here
		ar>>count;
		for(index=0;index<count;index++)
		{
			CLine *pLine = new CLine;
			ar>>pLine;
			m_obLineArray.Add(pLine);
		}
		
		ar>>count;
		for(index=0;index<count;index++)
		{
			CRectangle *pRect = new CRectangle;
			ar>>pRect;
			m_obRectArray.Add(pRect);
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CPaintDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CPaintDoc commands

void CPaintDoc::DeleteContents() 
{
	// TODO: Add your specialized code here and/or call the base class
	int count = m_obLineArray.GetSize();
	int position;
	if(count)
	{
		for(position=0;position<count;position++)
			delete m_obLineArray[position];
		m_obLineArray.RemoveAll();
	}
	count = m_obRectArray.GetSize();
	if(count)
	{
		for(position=0;position<count;position++)
			delete m_obRectArray[position];
		m_obRectArray.RemoveAll();
	}
	CDocument::DeleteContents();		

}

CLine * CPaintDoc::AddLine(CLine *ptLine)
{
	try
	{
		m_obLineArray.Add(ptLine);
		SetModifiedFlag();
	}
	catch (CMemoryException *perr) 
	{
		AfxMessageBox("Line:out of memory",MB_ICONSTOP|MB_OK);
		if(ptLine)
		{
			delete ptLine;
			ptLine = NULL;
		}
		perr->Delete();
	}
	return ptLine;
}

CRectangle * CPaintDoc::AddRect(CRectangle *ptRect)
{
	try
	{
		m_obRectArray.Add(ptRect);
		SetModifiedFlag();
	}
	catch (CMemoryException *perr) 
	{
		AfxMessageBox("Rectangle:out of memory",MB_ICONSTOP|MB_OK);
		if(ptRect)
		{
			delete ptRect;
			ptRect = NULL;
		}
		perr->Delete();
	}
	return ptRect;
}

⌨️ 快捷键说明

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