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

📄 zcr14paintdoc.cpp

📁 一个画笔的程序,可以进行直线,圆和方形等图形进行画图,并可以撤消上一步的动作
💻 CPP
字号:
// ZCR14PaintDoc.cpp : implementation of the CZCR14PaintDoc class
//

#include "stdafx.h"
#include "ZCR14Paint.h"
#include "ZCR14Shape.h"

#include "ZCR14PaintDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintDoc

IMPLEMENT_DYNCREATE(CZCR14PaintDoc, CDocument)

BEGIN_MESSAGE_MAP(CZCR14PaintDoc, CDocument)
	//{{AFX_MSG_MAP(CZCR14PaintDoc)
	ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
	ON_COMMAND(ID_FILE_REDO, OnFileRedo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintDoc construction/destruction

CZCR14PaintDoc::CZCR14PaintDoc()
{
	// TODO: add one-time construction code here
    m_emState=STATE_BLANK;
}

CZCR14PaintDoc::~CZCR14PaintDoc()
{
}

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

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
    //DeleteContents();
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintDoc serialization

void CZCR14PaintDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{   
	   //ar <<(INT)m_emState<<(INT)m_savedShapeCount<<(CString)m_strFileName;
		
       m_lstShape.Serialize(ar);
		// TODO: add storing code here
	}
	else
	{
       //ar >>(INT&)m_emState>>(INT&)m_savedShapeCount>>(CString&)m_strFileName;
       m_lstShape.Serialize(ar);
		// TODO: add loading code here
		
	}
}

/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CZCR14PaintDoc commands


CString CZCR14PaintDoc::GetFilePostfix(CString cstrPathName)
{
  CString Filefix=cstrPathName.Right(4);
  return Filefix;
}



void CZCR14PaintDoc::OnFileSaveAs() 
{
	// TODO: Add your command handler code here
	if (m_emState==STATE_BLANK)
		return;
	//if (m_lstShape.IsEmpty())
	//{
	//	AfxMessageBox("文件为空!");
//	}
	//else
	//{
	// 2. 打开“文件保存对话框”
	char BASED_CODE szFilter[] ="工程文件 (*.shp)|*.shp||";
	 		//CString strFileName= // 缺省文件名
	 		CFileDialog dlgFileSaveAs ( FALSE, "shp", "*.shp", 
				OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, 
				szFilter, AfxGetMainWnd() );	
			if ( dlgFileSaveAs.DoModal() != IDOK ) 
				return; // 如果不成功,退出!
			strPathName=dlgFileSaveAs.GetPathName();
			CString strExt=GetFilePostfix(strPathName);
			if(strExt.IsEmpty()||strExt!=".shp")
				strPathName+=".shp";
                SetSavedShapeCount();
			if(OnSaveDocument(strPathName)==TRUE)
			{
				AfxMessageBox("文件保存成功");
	            m_emState=STATE_SAVED;
			}
			else
				AfxMessageBox("文件保存失败");
			m_strFileName=strPathName;
//	}
	
}

void CZCR14PaintDoc::OnFileSave() 
{
	// TODO: Add your command handler code here
	// 2. 如果文件名为空或该文件不存在
	if(m_emState==STATE_MODIFIED)
	{
	
	   if ( strPathName.IsEmpty()||!FileIsExist(strPathName))
	   {
		OnFileSaveAs(); 
	   }
	     else // 3. 如果该文件已存在
		 {
		    CString strPrompt;
	     	if ( OnSaveDocument(strPathName)==FALSE ) 
			AfxMessageBox("文件保存失败!");
		 }
	}
	else 
		return;
	
}



int CZCR14PaintDoc::GetState()
{
  return m_emState;
}

void CZCR14PaintDoc::SetStateBlank()
{
  m_emState=STATE_BLANK;
}

void CZCR14PaintDoc::SetStateModified()
{
  m_emState=STATE_MODIFIED;
}

void CZCR14PaintDoc::SetStateSaved()
{
  m_emState=STATE_SAVED;
}



BOOL CZCR14PaintDoc::FileIsExist(CString strPathName)
{
	CFileStatus  fStatus;
	if(CFile::GetStatus(strPathName,fStatus))
	{
		return TRUE;
	}
	else
	{
		return FALSE;
	}

}

void CZCR14PaintDoc::SetSavedShapeCount()
{
       m_savedShapeCount =m_lstShape.GetCount();
}



void CZCR14PaintDoc::OnEditUndo() 
{
	// TODO: Add your command handler code here
	int num = m_lstShape.GetCount();
	POSITION pos = m_lstShape.GetTailPosition();
    if(num>0)
	{
		CZCR14Shape* pShape =
			(CZCR14Shape*)m_lstShape.GetAt(pos);
		m_lstUndo.AddTail(pShape);
        m_lstShape.RemoveAt(pos);
	}
	UpdateAllViews(NULL);
}

void CZCR14PaintDoc::OnFileRedo() 
{
	// TODO: Add your command handler code here
	int num = m_lstUndo.GetCount();
	POSITION pos = m_lstUndo.GetTailPosition();
    if(num>0)
	{
		CZCR14Shape* pShape =
			(CZCR14Shape*)m_lstUndo.GetAt(pos);
		m_lstShape.AddTail(pShape);
        m_lstUndo.RemoveAt(pos);
	}
	UpdateAllViews(NULL);
}

void CZCR14PaintDoc::DeleteContents()
{
   m_lstShape.DelateAll();
}

⌨️ 快捷键说明

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