CString szFilter = _T("hdc22_rx_keys_saved"); // 这样重加载文件类型时规避了异常
CFolderPickerDialog objFileDlg(
szFilter,/*LPCTSTR lpszFolder = NULL,*/
OFN_READONLY,/*DWORD dwFlags = 0,*/
NULL,/*CWnd* pParentWnd = NULL,*/
0/*DWORD dwSize = 0*/
);
if (objFileDlg.DoModal() == IDOK)
{
CString outputPath(objFileDlg.GetPathName());
//CString outputPath(objFileDlg.GetFolderPath());
if(!PathIsDirectory(outputPath))
{
//for XP which CFolderPickerDialog cannot work
outputPath = outputPath.Left(outputPath.ReverseFind('\\'));
}
if(!PathIsDirectoryEmpty(outputPath)){
//MessageBox(_T("请选择一个空的目录"));
_MSG_BOX_ERR(_T("[%s]不是一个存在的空目录"), outputPath);
return;
}
}
私がデバッグしたように、CFolderPickerDialog は win7/win10 で検索できますが、CFileDialog と同じようにファイルを選択することしかできません。上記は私の回避策を示しています。ユーザーに szFilter で終わるファイルを選択させ、 CString::Left を使用して正しいフォルダーを取得します。