原文: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.
- //读取注册文件。
- CString username;
- CFile file;
- file.Open(_T("user.dat"), CFile::modeRead|CFile::modeCreate|CFile::modeNoTruncate, NULL);//保留源文件内容。
- if (file.GetLength() == 0)
- {
-
- GetDlgItem(IDC_ENTER)->EnableWindow(FALSE);
- GetDlgItem(IDC_REGISTER)->EnableWindow(TRUE);
- MessageBox("您还没有注册,请点击注册按钮进行注册。");
- }
- else
- {
- GetDlgItem(IDC_ENTER)->EnableWindow(TRUE);
- GetDlgItem(IDC_REGISTER)->EnableWindow(FALSE);
- }
- file.Close();