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

📄 sdocdemodoc.cpp

📁 VC++6开发指南的源代码第7章-第11章
💻 CPP
字号:
// SDocDemoDoc.cpp : implementation of the CSDocDemoDoc class
//

#include "stdafx.h"
#include "SDocDemo.h"

#include "SDocDemoDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoDoc

IMPLEMENT_DYNCREATE(CSDocDemoDoc, CDocument)

BEGIN_MESSAGE_MAP(CSDocDemoDoc, CDocument)
	//{{AFX_MSG_MAP(CSDocDemoDoc)
	ON_COMMAND(ID_UNDO, OnUndo)
	ON_UPDATE_COMMAND_UI(ID_UNDO, OnUpdateUndo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoDoc construction/destruction

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

}

CSDocDemoDoc::~CSDocDemoDoc()
{
}

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

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

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CSDocDemoDoc serialization

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

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoDoc diagnostics

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

void CSDocDemoDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}


void CSDocDemoDoc::AddLine(int StartX,int StartY,int EndX,int EndY)//添加线条
{
	CLineDraw *pLine=new CLineDraw(StartX,StartY,EndX,EndY);
	m_lineArray.Add(pLine);//加入数组类
	SetModifiedFlag();
}

CLineDraw *CSDocDemoDoc::GetLine(int index)
{
	if(index<0||index>m_lineArray.GetUpperBound())//无效的线条
		return 0;
	return (CLineDraw *)m_lineArray.GetAt(index);//从数组中获取线条指针
}

int CSDocDemoDoc::GetTotalLine()
{
	return m_lineArray.GetSize();//数组中存储的线条数目
}



#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSDocDemoDoc commands

void CSDocDemoDoc::DeleteContents() 
{
	// TODO: Add your specialized code here and/or call the base class
	int index;
	index=m_lineArray.GetSize();//获取线条的数目
	while(index--)
		delete m_lineArray.GetAt(index);//删除数组元素
	m_lineArray.RemoveAll();//删除数组对象	
	CDocument::DeleteContents();
}

void CSDocDemoDoc::OnUndo() 
{
	// TODO: Add your command handler code here
	int index;
	index=m_lineArray.GetUpperBound();//获取数组最后的元素
	if(index>=0)
	{
		delete m_lineArray.GetAt(index);
		m_lineArray.RemoveAt(index);//删除线条
	}
	UpdateAllViews(NULL);
	SetModifiedFlag();
}

void CSDocDemoDoc::OnUpdateUndo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_lineArray.GetSize());//只有线条数组不为空菜单命令项才有效
}

⌨️ 快捷键说明

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