(转)记录:VC++中打开保存目录选择对话框操作
//打开文件对话框
const char pszFilter[] = _T("EXE File (*.txt)|*.txt|All Files (*.*)|*.*||"); CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, pszFilter, this); dlg.m_ofn.lpstrInitialDir = "c:\\WINDOWS\\" //设置对话框默认呈现的路径 if(dlg.DoModal() == IDOK) { CString strFilePath = dlg.GetPathName(); /*如果有多个文件,则 for(POSITION pos = dlg.GetStartPosition(); pos!=NULL; ) { CString strFilePathName = dlg.GetNextPathName(pos);}*/ }
//保存文件对话框
const char pszFilter[] = _T("EXE Files (*.txt)|*.txt||"); CFileDialog dlgSave( FALSE, //FALSE为保存 _T(".txt"), //自动加上的扩展名 _T("Output.txt"), //默认保存的文件名 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, pszFilter, this);
//目录选择对话框
TCHAR szPath[MAX_PATH]; BROWSEINFO br; ITEMIDLIST * pItem; br.hwndOwner = this->GetSafeHwnd(); br.iImage = 0; br.pszDisplayName = 0; br.lParam = 0 ; br.lpfn = 0 ; br.lpszTitle = _T("请选择路径"); br.pidlRoot = 0 ; br.ulFlags = BIF_RETURNONLYFSDIRS; pItem = SHBrowseForFolder(&br); if ( SHGetPathFromIDList(pItem,szPath) == TRUE) { //m_edtPath.SetWindowText( szPath); }