CFileDialog :: Browse folders

后端 未结 6 1055
野性不改
野性不改 2020-12-17 22:39

When I try to instantiate a CFileDialog object it shows both the folders and files. How do you create a CFileDialog that browses for folders alone?

6条回答
  •  温柔的废话
    2020-12-17 23:16

    Seems to me the answer you are asking for is inside the code of

    CMFCPropertyGridFileProperty::OnClickButton(CPoint /*point*/)
    

    of the

    \VC\atlmfc\src\mfc\afxpropertygridctrl.cpp
    

    file.

    If you do not have access to the code, I will post the essential part of it:

    CString strPath = m_varValue.bstrVal;
    BOOL bUpdate = FALSE;
    
    if (m_bIsFolder)
    {
        if (afxShellManager == NULL)
        {
            CWinAppEx* pApp = DYNAMIC_DOWNCAST(CWinAppEx, AfxGetApp());
            if (pApp != NULL)
            {
                pApp->InitShellManager();
            }
        }
    
        if (afxShellManager == NULL)
        {
            ASSERT(FALSE);
        }
        else
        {
            bUpdate = afxShellManager->BrowseForFolder(strPath, m_pWndList, strPath);
        }
    }
    else
    {
        CFileDialog dlg(m_bOpenFileDialog, m_strDefExt, strPath, m_dwFileOpenFlags, m_strFilter, m_pWndList);
        if (dlg.DoModal() == IDOK)
        {
            bUpdate = TRUE;
            strPath = dlg.GetPathName();
        }
    }
    

    As you see, Microsoft itself does not use the Cfiledialog class when wants to open a dialog for picking folders.

    For using code like that, your application class MUST be derived from CWinAppEx, not CWinApp

提交回复
热议问题