📄 mydrawdoc.cpp
字号:
// MyDrawDoc.cpp : implementation of the CMyDrawDoc class
//
#include "stdafx.h"
#include "MyDraw.h"
#include "MyDrawDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc
IMPLEMENT_DYNCREATE(CMyDrawDoc, CDocument)
BEGIN_MESSAGE_MAP(CMyDrawDoc, CDocument)
//{{AFX_MSG_MAP(CMyDrawDoc)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc construction/destruction
CMyDrawDoc::CMyDrawDoc()
{
// TODO: add one-time construction code here
}
CMyDrawDoc::~CMyDrawDoc()
{
}
BOOL CMyDrawDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
void CMyDrawDoc::AddLine(CPoint pt1, CPoint pt2)
{
CLine * pLine=new CLine(pt1, pt2); // 新建一条线段对象
m_LineArray.Add(pLine); // 将该线段对象加到动态数组
SetModifiedFlag(); // 设置文档修改标志
}
CLine * CMyDrawDoc::GetLine(int nIndex)
{
if(nIndex<0||nIndex>m_LineArray.GetUpperBound()) // 判断是否越界
return NULL;
return m_LineArray.GetAt(nIndex); // 返回给定序号线段对象的指针
}
int CMyDrawDoc::GetNumLines()
{
return m_LineArray.GetSize(); // 返回线段的数量
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc serialization
void CMyDrawDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
m_LineArray.Serialize(ar); // 调用CObArray类的序列化函数
}
else
{
// TODO: add loading code here
m_LineArray.Serialize(ar);
}
}
/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc diagnostics
#ifdef _DEBUG
void CMyDrawDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CMyDrawDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyDrawDoc commands
void CMyDrawDoc::DeleteContents() // 重载成员函数,清除当前文档的内容
{
// TODO: Add your specialized code here and/or call the base class
int nIndex=GetNumLines();
while(nIndex--)
delete m_LineArray.GetAt(nIndex); // 清除线段
m_LineArray.RemoveAll(); // 释放指针数组
CDocument::DeleteContents();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -