打開文件對話框
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);
目錄選擇對話框
?BROWSEINFO bi;
?char szPathName[MAX_PATH];
?char szTitle[] = "選擇路徑";
?ZeroMemory(&bi, sizeof(BROWSEINFO));
?
?bi.hwndOwner = GetSafeHwnd();
?bi.pszDisplayName = szPathName;
?bi.lpszTitle = szTitle;
?bi.ulFlags = 0x0040 ;
?CString str;
CString strDir;? //選擇的目錄
?LPITEMIDLIST idl = SHBrowseForFolder(&bi);
?if(idl == NULL)
?{
??strDir= "";
??return;
?}
?
?SHGetPathFromIDList(idl, str.GetBuffer(MAX_PATH * 2));
?str.ReleaseBuffer();
?if(str != "" && str.GetAt(str.GetLength() - 1) != '\\')
??str += "\\";
?strDir = str;