CFileDialog 类是否支持用户选择文件夹功能?
时间: 2024-11-22 19:43:33 浏览: 44
`CFileDialog` 是 MFC (Microsoft Foundation Classes) 提供的一个用于弹出文件或目录选择对话框的类。它确实支持用户选择文件夹的功能,你可以通过设置 `OFN_ALLOWMULTISELECT` 和 `OFN_DIRNAMEONLY` 标志来指定允许选择多个目录或仅限于选择当前目录作为根目录。
例如,在C++中,你可以这样做:
```cpp
CFileDialog dialog(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_DIRNAMEONLY);
if (dialog.DoModal() == IDOK)
{
// 获取选中的文件夹路径列表
vector<string> folders;
for (LPCTSTR folder = dialog.GetPathName(); *folder; ++folder)
folders.push_back(folder);
}
```
阅读全文
相关推荐















