1 TCHAR szFolderPath[MAX_PATH] = {0}; 2 CString strFolderPath = ""; 3 BROWSEINFO sInfo; 4 ZeroMemory(&sInfo, sizeof(BROWSEINFO)); 5 6 sInfo.pidlRoot = 0; 7 sInfo.lpszTitle = "请选择一个文件夹:"; 8 sInfo.ulFlags = BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | BIF_EDITBOX; 9 sInfo.lpfn = NULL; 10 11 // 显示文件夹选择对话框 12 LPITEMIDLIST lpidlBrowse = SHBrowseForFolder(&sInfo); 13 if (lpidlBrowse != NULL) 14 { 15 // 取得文件夹名 16 if (SHGetPathFromIDList(lpidlBrowse,szFolderPath)) 17 { 18 strFolderPath = szFolderPath; 19 } 20 } 21 if(lpidlBrowse != NULL) 22 { 23 CoTaskMemFree(lpidlBrowse); 24 }