📄 mydiary.cpp
字号:
// MyDiary.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "MyDiary.h"
#include "MyDiaryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDiaryApp
BEGIN_MESSAGE_MAP(CMyDiaryApp, CWinApp)
//{{AFX_MSG_MAP(CMyDiaryApp)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CMyDiaryApp construction
CMyDiaryApp::CMyDiaryApp()
{
is_old = FALSE;
m_pos = NULL;
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CMyDiaryApp object
CMyDiaryApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CMyDiaryApp initialization
BOOL CMyDiaryApp::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.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CMyDiaryDlg 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 CMyDiaryApp::Serialize(CArchive& ar)
{
POSITION pos;
WORD nCount;
if (ar.IsStoring())
{ // storing
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
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 CMyDiaryApp::onSave() //存储
{
CFile file;
if(file.Open("diary.dia", CFile::modeCreate|CFile::modeWrite))
{
CArchive ar(&file, CArchive::store);
Serialize(ar);
ar.Close();
file.Close();
}
}
void CMyDiaryApp::onRead()//读出
{
CFile file;
if(file.Open("diary.dia", CFile::modeRead))
{
CArchive ar(&file, CArchive::load);
Serialize(ar);
ar.Close();
file.Close();
}
}
CString CMyDiaryApp::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);
//Converts a floating-point value to a string, which it stores in a buffer.
//char *_gcvt( double value, int digits, char *buffer );
m_date = (CString)m_chyear + "年" + (CString)m_chmonth + "月" + (CString)m_chday + "日";
return m_date;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -