0

I develop with Visual Studio 2008 (Windows 7) and use

CFileDialog(TRUE, NULL, lastPath, NULL, szFilter);

The important parameter is the third (lastPath) to get in a specific directory! All works fine with Windows 7 but in Windows 2000 the Dialog only works if lastPath (LPCTSTR lpszFileName) is empty (otherwise the Dialog doesn't open)

Any ideas!?

Thanks and greets leon22

leon22
  • 5,280
  • 19
  • 62
  • 100

2 Answers2

0
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;
    }

}

As I debugged, CFolderPickerDialog can work find in win7/win10, but can only select file just like CFileDialog. Above shows my workaround, I make user select a file ends with szFilter , and using CString::Left to get the correct folder.

huigege
  • 11
  • 1
0

Ok, I have found the error:

don't set the initial directory with lpszFileName!

Right usage:

CFileDialog oDlg(TRUE, NULL, NULL, NULL, szFilter);
oDlg.m_ofn.lpstrInitialDir = lastPath.GetBuffer(0); // set initial dir

greets leon22

leon22
  • 5,280
  • 19
  • 62
  • 100