打开文件对话框:打开.txt文件例子
CFileDialog dlg(TRUE, _T("txt"),NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("TXT Files (*.txt)|*.txt||"),this);
if (dlg.DoModal() == IDOK)
{
m_StrOpenPath = dlg.GetPathName(); //获取文件名称与路径
}
选择保存文件路径对话框:
char buf[MAX_PATH];
memset(buf,0,sizeof(buf));
BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = buf;
bi.lpszTitle = _T("请选择保存的目录:");
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
bi.iImage = 0;
LPITEMIDLIST lp = SHBrowseForFolder(&bi);
if(lp && SHGetPathFromIDList(lp,buf))
{
m_StrSavePath.Format(_T("%s"),buf);
}
else
{
AfxMessageBox(_T("目录无效!"),MB_OK,0);
}
//创建读文件操作指针
//CStdioFile *pReadFile = new CStdioFile(m_StrOpenPath, CFile::modeRead | CFile::shareDenyNone);
//创建一个读写文件操作指针
//CStdioFile *pWriteFile = new CStdioFile(m_StrSavePath, CFile::modeRead | CFile::shareDenyNone | CFile::modeWrite |CFile::modeCreate);
/*
while(pReadFile->ReadString(strTemp)) //读一行数据
{
pWriteFile->WriteString(strTemp); //写一行数据
}*/