文件保存:
//为FALSE,显示保存文件对话框
CFileDialog fileDlg(FALSE);
fileDlg.m_ofn.lpstrTitle = "我的文件保存对话框";
fileDlg.m_ofn.lpstrFilter = "Text Files(*.txt) *.txt All Files(*.*) *.* ";
fileDlg.m_ofn.lpstrDefExt = "txt";
if (IDOK == fileDlg.DoModal())
{
CFile file(fileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
file.Write(_T("minzhenfei"), strlen(_T("minzhenfei")));
file.Close();
}
文件打开:
//为true,显示打开文件对话框
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle = "我的文件打开对话框";
fileDlg.m_ofn.lpstrFilter = "Text Files(*.txt) *.txt All Files(*.*) *.* ";
if (IDOK == fileDlg.DoModal())
{
CFile fileRead(fileDlg.GetFileName(), CFile::modeRead);
CHAR *pBuf;
DWORD strlen;
strlen = fileRead.GetLength();
pBuf = new CHAR[strlen + 1];
fileRead.Read(pBuf, strlen);
pBuf[strlen] = 0;
fileRead.Close();
MessageBox(pBuf);
}