弹出选择文件路径的资源管理器窗口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
CString ShowDlg_GetPath() { CString strFolderPath = TEXT(""); BROWSEINFO ofn; TCHAR szFile[MAX_PATH] = _T(""); ZeroMemory(&ofn, sizeof(ofn)); ofn.pidlRoot = 0; ofn.lpszTitle = _T("请选择一个文件夹:"); ofn.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_EDITBOX; ofn.lpfn = nullptr; LPITEMIDLIST lpidIBrowse = ::SHBrowseForFolder(&ofn); if (lpidIBrowse != nullptr) { if(::SHGetPathFromIDList(lpidIBrowse, szFile)) { //对保存的路径szFile进行处理 strFolderPath = szFile; } } if (lpidIBrowse != nullptr) ::CoTaskMemFree(lpidIBrowse); return strFolderPath; } |
- 220722更新,pidlRoot为NULL的时候,有几率在个别环境下出现看不到盘符的情况,修改如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
void CMainDlg::OnChangePath() { BROWSEINFO ofn; TCHAR szFile[MAX_PATH] = _T(""); LPITEMIDLIST pidl = NULL; SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &pidl); ZeroMemory(&ofn, sizeof(ofn)); ofn.pidlRoot = pidl; ofn.lpszTitle = _T("请选择安装路径:"); ofn.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE | BIF_EDITBOX; ofn.lpfn = nullptr; ofn.lParam = NULL; LPITEMIDLIST lpidIBrowse = ::SHBrowseForFolder(&ofn); if (lpidIBrowse != nullptr) { if (::SHGetPathFromIDList(lpidIBrowse, szFile)) { m_strSelPath = szFile; m_strSelPath.Append(L"\\aet"); } } if (lpidIBrowse != nullptr) { UpdatePath(); ::CoTaskMemFree(lpidIBrowse); } } |
弹出选择某文件的资源管理器窗口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
void ShowDlg_SelectFile() { OPENFILENAME ofn; TCHAR szFile[MAX_PATH] = _T(""); ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = *this; ofn.lpstrFile = szFile; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = STR_FILE_FILTER; ofn.nFilterIndex = 1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir = NULL; ofn.Flags = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST; if(GetOpenFileName(&ofn)) { std::vector<string_t> vctString(1,szFile); } } |
本文为原创文章,版权归Aet所有,欢迎分享本文,转载请保留出处!
你可能也喜欢
- ♥ MFC 自定义消息04/29
- ♥ 逐行读取txt内容10/12
- ♥ Duilib切换界面区域布局11/04
- ♥ System_系统是否为64位操作系统10/19
- ♥ 非阻塞版本 Sleep实现10/12
- ♥ Duilib_概念&&标签05/22