VC保存文件的参考代码

<script type="text/javascript"> </script> <script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script> 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">
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();
}
*/
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值