📄 diary.cpp
字号:
// Diary.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Diary.h"
#include "DiaryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDiaryApp
BEGIN_MESSAGE_MAP(CDiaryApp, CWinApp)
//{{AFX_MSG_MAP(CDiaryApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDiaryApp construction
CDiaryApp::CDiaryApp()
{
is_old = FALSE;
m_pos = NULL;
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CDiaryApp object
CDiaryApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDiaryApp initialization
BOOL CDiaryApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
CDiaryDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
void CDiaryApp::Serialize(CArchive& ar)
{
POSITION pos;
WORD nCount;
if (ar.IsStoring())
{ // storing code
nCount = (WORD)m_diaryList.GetCount();
ar << nCount;
pos = m_diaryList.GetHeadPosition();
while(pos != NULL)
{
CMyDiary* pMyDiary = m_diaryList.GetNext(pos);
ar << pMyDiary->m_TDate;
ar << pMyDiary->m_strWeek;
ar << pMyDiary->m_strWeather;
ar << pMyDiary->m_strBody;
nCount --;
}
ASSERT(nCount == 0);
}
else
{ // loading code
ar >> nCount;
while(nCount -- > 0)
{
CMyDiary* pMyDiary = new CMyDiary;
ar >> pMyDiary->m_TDate;
ar >> pMyDiary->m_strWeek;
ar >> pMyDiary->m_strWeather;
ar >> pMyDiary->m_strBody;
m_diaryList.AddTail(pMyDiary);
}
}
}
void CDiaryApp::onSave()
{
CFile file;
if(file.Open("diary.dia", CFile::modeCreate|CFile::modeWrite))
{
CArchive ar(&file, CArchive::store);
Serialize(ar);
ar.Close();
file.Close();
}
}
void CDiaryApp::onRead()
{
CFile file;
if(file.Open("diary.dia", CFile::modeRead))
{
CArchive ar(&file, CArchive::load);
Serialize(ar);
ar.Close();
file.Close();
}
}
CString CDiaryApp::TimetoCString(CTime& m_Ttime)
{
int m_nyear, m_nmonth, m_nday;
CString m_date;;
char m_chyear[9], m_chmonth[5], m_chday[5];
m_nyear = m_Ttime.GetYear();
m_nmonth = m_Ttime.GetMonth();
m_nday = m_Ttime.GetDay();
_gcvt((double)m_nyear, 4, m_chyear);
_gcvt((double)m_nmonth, 2, m_chmonth);
_gcvt((double)m_nday, 2, m_chday);
m_date = (CString)m_chyear + "年" + (CString)m_chmonth + "月" + (CString)m_chday + "日";
return m_date;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -