0%

MFC使用文件夹选择对话框

  1. CFolderPickerDialog

CFolderPickerDialog

https://docs.microsoft.com/zh-cn/cpp/mfc/reference/cfolderpickerdialog-class

1
2
3
4
5
6
CFolderPickerDialog dlg;

if (dlg.DoModal() == IDOK)
{
CString folderPath = dlg.GetFolderPath();
}

创建对话框实例后,调用DoModal()显示对话框

通过GetFolderPath()函数(CFileDialog 类 | Microsoft Docs)获取文件夹路径

效果:

image-20220602154411316

  • 可以输入路径直达文件夹
  • 可以搜索文件夹内容
  • 左侧为系统文件树,包含“此电脑”、“网络邻居”、“快速访问”等