📄 tipreaderdoc.cpp
字号:
// TipReaderDoc.cpp : implementation of the CTipReaderDoc class
//
#include "stdafx.h"
#include "TipReader.h"
#include "FileView.h"
#include "TipReaderDoc.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTipReaderDoc
IMPLEMENT_DYNCREATE(CTipReaderDoc, CDocument)
BEGIN_MESSAGE_MAP(CTipReaderDoc, CDocument)
//{{AFX_MSG_MAP(CTipReaderDoc)
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTipReaderDoc construction/destruction
CTipReaderDoc::CTipReaderDoc()
{
// TODO: add one-time construction code here
}
CTipReaderDoc::~CTipReaderDoc()
{
}
BOOL CTipReaderDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
((CEditView *)((CSplitterWnd*)this->m_pEditView->GetParent())->GetPane(0,1))->SetFont(&(((CTipReaderApp *)::AfxGetApp())->m_config.m_font),TRUE);
this->SetTitle(((CTipReaderApp *)::AfxGetApp())->m_config.m_filename);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CTipReaderDoc serialization
void CTipReaderDoc::Serialize(CArchive& ar)
{
// CEditView contains an edit control which handles all serialization
CString temp1,temp2;
this->m_pEditView->SerializeRaw(ar);
if(ar.IsLoading())
{
temp1=ar.GetFile()->GetFilePath();
temp2=ar.GetFile()->GetFileName();
temp1=temp1.Left(temp1.GetLength()-temp2.GetLength());
((CTipReaderApp *)::AfxGetApp())->m_config.m_path=temp1;
((CFileView *)((CSplitterWnd*)this->m_pEditView->GetParent())->GetPane(0,0))->SetTree();
((CTipReaderApp *)::AfxGetApp())->m_config.m_filename=ar.GetFile()->GetFileName();
}
}
/////////////////////////////////////////////////////////////////////////////
// CTipReaderDoc diagnostics
#ifdef _DEBUG
void CTipReaderDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CTipReaderDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTipReaderDoc commands
BOOL CTipReaderDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
((CEditView *)((CSplitterWnd*)this->m_pEditView->GetParent())->GetPane(0,1))->SetFont(&(((CTipReaderApp *)::AfxGetApp())->m_config.m_font),TRUE);
return TRUE;
}
void CTipReaderDoc::OnFileSave()
{
// TODO: Add your command handler code here
if(((CTipReaderApp *)::AfxGetApp())->m_config.m_filename!="NULL")
{
CString path,filename;
path=((CTipReaderApp *)::AfxGetApp())->m_config.m_path;
filename=path+((CTipReaderApp *)::AfxGetApp())->m_config.m_filename;
CFile m_file;
CString text;
::DeleteFile(filename);
if(!m_file.Open(filename,CFile::modeCreate,NULL))
::AfxMessageBox("有错误发生!");
else
{
m_file.Close();
if(m_file.Open(filename,CFile::modeWrite,NULL))
{
CArchive ar(&m_file,CArchive::store,4096,NULL);
this->m_pEditView->GetEditCtrl().GetWindowText(text);
ar.WriteString(text);
ar.Close();
}
}
}
}
void CTipReaderDoc::OnCloseDocument()
{
// TODO: Add your specialized code here and/or call the base class
// CDocument::OnCloseDocument();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -