CFile 深入研究之 CFile::modeNoTruncate

原文:CFile 深入研究之 CFile::modeNoTruncate

即时通讯爱好者 NanShan 最近专注于研究 CFile 的各种问题,今天主要是 CFile::modeNoTruncate 相信研究。

CFile::modeNoTruncate Combine this value with modeCreate. If the file being created already exists, it is not truncated to 0 length. Thus the file is guaranteed to open, either as a newly created file or as an existing file. This might be useful, for example, when opening a settings file that may or may not exist already. This option applies to CStdioFile as well.

  1. ////////////////////////////////////////////////////////
  2. //读取注册文件。
  3.     CString username;
  4.     CFile file;
  5.     file.Open(_T("user.dat"), CFile::modeRead|CFile::modeCreate|CFile::modeNoTruncate, NULL);//保留源文件内容。
  6.     if (file.GetLength() == 0)
  7.     {
  8.         
  9.         GetDlgItem(IDC_ENTER)->EnableWindow(FALSE);
  10.         GetDlgItem(IDC_REGISTER)->EnableWindow(TRUE);
  11.         MessageBox("您还没有注册,请点击注册按钮进行注册。");
  12.     }
  13.     else
  14.     {
  15.         GetDlgItem(IDC_ENTER)->EnableWindow(TRUE);
  16.         GetDlgItem(IDC_REGISTER)->EnableWindow(FALSE);
  17.     }
  18.     file.Close();
复制代码


你可能感兴趣的:(close,modeNoTruncate,GetDlgItem)