void CDiaryDlg::OnButtonSave()
{
// TODO: Add your control notification handler code here
// 這種用bSave的方式來判斷是否保存過,這樣不好,待考慮。
// if (!bSave)
{
int iYear = m_cMonthVIEw.GetYear();
int iMonth = m_cMonthVIEw.GetMonth();
int iDay = m_cMonthVIEw.GetDay();
CString sFileName;
sFileName.Format("%d-%d-%d.txt", iYear, iMonth, iDay);
CFileDialog dlg(FALSE, "txt", sFileName,
OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY,
"文本文件(*.txt)|*.txt||", this);
dlg.m_ofn.lpstrTitle = _T("保存日記文件");
if (dlg.DoModal() == IDOK)
{
// 實現存盤
CString fileName = dlg.GetPathName();
CFile file(fileName, CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive);
CArchive ar(&file, CArchive::store|CArchive::bNoFlushOnDelete);
UpdateData(TRUE);
ar<<m_sComment;
ar.Close();
bSave = TRUE;
m_sFileName = fileName;
}
}
/*
else
{
CFile file(m_sFileName, CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive);
CArchive ar(&file, CArchive::store|CArchive::bNoFlushOnDelete);
UpdateData(TRUE);
ar<<m_sComment;
ar.Close();
}
*/
}