?? sdocdemodoc.cpp
字號(hào):
// 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);//加入數(shù)組類
SetModifiedFlag();
}
CLineDraw *CSDocDemoDoc::GetLine(int index)
{
if(index<0||index>m_lineArray.GetUpperBound())//無效的線條
return 0;
return (CLineDraw *)m_lineArray.GetAt(index);//從數(shù)組中獲取線條指針
}
int CSDocDemoDoc::GetTotalLine()
{
return m_lineArray.GetSize();//數(shù)組中存儲(chǔ)的線條數(shù)目
}
#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();//獲取線條的數(shù)目
while(index--)
delete m_lineArray.GetAt(index);//刪除數(shù)組元素
m_lineArray.RemoveAll();//刪除數(shù)組對(duì)象
CDocument::DeleteContents();
}
void CSDocDemoDoc::OnUndo()
{
// TODO: Add your command handler code here
int index;
index=m_lineArray.GetUpperBound();//獲取數(shù)組最后的元素
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());//只有線條數(shù)組不為空菜單命令項(xiàng)才有效
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -