|
打開(kāi)文件對(duì)話框 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\\"; //設(shè)置對(duì)話框默認(rèn)呈現(xiàn)的路徑
if(dlg.DoModal() == IDOK) { CString strFilePath = dlg.GetPathName(); /*如果有多個(gè)文件,則 for(POSITION pos = dlg.GetStartPosition(); pos!=NULL; ) { CString strFilePathName = dlg.GetNextPathName(pos); */ }
保存文件對(duì)話框 const char pszFilter[] = _T("EXE Files (*.txt)|*.txt||"); CFileDialog dlgSave( FALSE, //FALSE為保存 _T(".txt"), //自動(dòng)加上的擴(kuò)展名 _T("Output.txt"), //默認(rèn)保存的文件名 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, pszFilter, this);
目錄選擇對(duì)話框
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;
posted on 2006-12-06 16:17 永遇樂(lè) 閱讀(10356) 評(píng)論(0) 編輯 收藏 引用 所屬分類: Windows MFC
|