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

📄 custdlgdoc.cpp

📁 讲mfc的书
💻 CPP
字号:
// custdlgDoc.cpp : implementation of the CCustdlgDoc class
//

#include "stdafx.h"
#include "custdlg.h"

#include "custdlgDoc.h"

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

/////////////////////////////
// CCustdlgDoc

IMPLEMENT_DYNCREATE(CCustdlgDoc, CDocument)

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

/////////////////////////////
// CCustdlgDoc construction/destruction

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

}

CCustdlgDoc::~CCustdlgDoc()
{
}

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

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

	return TRUE;
}



/////////////////////////////
// CCustdlgDoc serialization

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

/////////////////////////////
// CCustdlgDoc diagnostics

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

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

/////////////////////////////
// CCustdlgDoc commands

// This is more or less a copy of the original
// version of DoSave, except it calls our version
// of DoPromptFileName
BOOL CCustdlgDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
{
	CString newName = lpszPathName;
	if (newName.IsEmpty())
	{
		CDocTemplate* pTemplate = GetDocTemplate();
		ASSERT(pTemplate != NULL);

		newName = m_strPathName;
		if (bReplace && newName.IsEmpty())
		{
			newName = m_strTitle;
#ifndef _MAC
			// check for dubious filename
			int iBad = newName.FindOneOf(_T(" #%;/\\"));
#else
			int iBad = newName.FindOneOf(_T(":"));
#endif
			if (iBad != -1)
				newName.ReleaseBuffer(iBad);

#ifndef _MAC
			// append the default suffix if there is one
			CString strExt;
			if (pTemplate->GetDocString(strExt, CDocTemplate::filterExt) &&
			  !strExt.IsEmpty())
			{
				ASSERT(strExt[0] == '.');
				newName += strExt;
			}
#endif
		}

		CCustdlgApp *app=(CCustdlgApp *)AfxGetApp();
		if (!app->DoPromptFileName(newName,
		  bReplace ? AFX_IDS_SAVEFILE : AFX_IDS_SAVEFILECOPY,
		  OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, pTemplate))
			return FALSE;       // don't even attempt to save
	}

	CWaitCursor wait;

	if (!OnSaveDocument(newName))
	{
		if (lpszPathName == NULL)
		{
			// be sure to delete the file
			TRY
			{
				CFile::Remove(newName);
			}
			CATCH_ALL(e)
			{
				TRACE0("Warning: failed to delete file after failed SaveAs.\n");
			}
			END_CATCH_ALL
		}
		return FALSE;
	}

  // reset the title and change the document name
  if (bReplace)
          SetPathName(newName);

  return TRUE;        // success

}

⌨️ 快捷键说明

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