标签:mfc cfiledlg browseinfo 获取文件夹路径
1.获取文件的路径
CFileDialog fileDlg(TRUE); fileDlg.m_ofn.lpstrTitle=L"打开文件"; //fileDlg.m_ofn.lpstrFilter=_T("Program(*.exe)\0*.exe\0All Files(*.*)\0*.*\0\0"); if(IDOK==fileDlg.DoModal()) { LPWSTR lpPathName = fileDlg.m_ofn.lpstrFile; SetDlgItemText(IDC_EDIT_SERV_PATH,lpPathName); }
typedef struct_browseinfo { HWND hwndOwner; LPCITEMIDLIST pidlRoot; LPSTR pszDisplayName; LPCSTR lpszTitle; UINT ulFlags; BFFCALLBACK lpfn; LPARAM lParam; int iImage; }BROWSEINFO,*PBROWSEINFO,*LPBROWSEINFO;
CString m_strFileOut = _T(""); TCHAR servPath[MAX_PATH];//用来存放文件夹路径 BROWSEINFO bi; LPITEMIDLIST pidl; bi.hwndOwner = this->m_hWnd; bi.pidlRoot = NULL; bi.pszDisplayName = servPath; bi.lpszTitle = _T("选择输出文件路径"); bi.ulFlags = BIF_RETURNONLYFSDIRS; bi.lpfn = NULL; bi.lParam = NULL; bi.iImage = NULL; if((pidl = SHBrowseForFolder(&bi)) != NULL) { if(SUCCEEDED(SHGetPathFromIDList(pidl, servPath))) //得到文件夹的全路径,不要的话,只得本文件夹名 { SetDlgItemText(IDC_EDIT_SERV_PATH,servPath); } }
标签:mfc cfiledlg browseinfo 获取文件夹路径
原文地址:http://blog.csdn.net/u013147600/article/details/42737107