VC保存文件的參考代碼

<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> <iframe name="google_ads_frame" marginwidth="0" marginheight="0" src="http://pagead2.googlesyndication.com/pagead/ads?client=ca-pub-6319745239117838&dt=1192361838062&lmt=1192361838&format=300x250_as&output=html&correlator=1192361838046&url=http%3A%2F%2Fwww.programfan.com%2Farticle%2Fshowarticle.asp%3Fid%3D2537&ad_type=text_image&ref=http%3A%2F%2Fwww.google.cn%2Fsearch%3Fcomplete%3D1%26hl%3Dzh-CN%26ie%3DGB2312%26q%3DVC%25B1%25A3%25B4%25E6%25CA%25FD%25BE%25DD%26meta%3D%26aq%3Dnull&cc=100&ga_vid=567952666.1192361838&ga_sid=1192361838&ga_hid=1651908726&flash=9&u_h=768&u_w=1024&u_ah=738&u_aw=1024&u_cd=32&u_tz=480&u_java=true" frameborder="0" width="300" scrolling="no" height="250" allowtransparency="allowtransparency"></iframe>
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();
}
*/
}
 
發佈了56 篇原創文章 · 獲贊 2 · 訪問量 17萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章