1 TCHAR szPath[MAX_PATH]; //存放选择的目录路径 2 CString str; 3 4 ZeroMemory(szPath, sizeof(szPath)); 5 6 BROWSEINFO bi; 7 bi.hwndOwner = m_hWnd; 8 bi.pidlRoot = NULL; 9 bi.pszDisplayName = szPath; 10 bi.lpszTitle = _T("请选择需要打开的目录:"); 11 bi.ulFlags = 0; 12 bi.lpfn = NULL; 13 bi.lParam = 0; 14 bi.iImage = 0; 15 //弹出选择目录对话框16 LPITEMIDLIST lp = SHBrowseForFolder(&bi); 17 18 if(lp && SHGetPathFromIDList(lp, szPath)) 19 {20 str.Format(_T("选择的目录为 %s"), szPath);21 AfxMessageBox(str); 22 }23 else 24 AfxMessageBox(_T("无效的目录,请重新选择"));