Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use IFileDialog with FOS_PICKFOLDER while still displaying file names in the dialog

Tags:

winapi

I'm trying to use IFileDialog to select a folder and the following code does this just fine. The problem is I'd like to see certain file types as well as folders while browsing (such as *.txt). Is there a simple way to do this?

//g_path is a global which will contain the selected folders path
void PickContainer()
{
    IFileDialog *pfd;
    if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
    {
        DWORD dwOptions;
        if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
        {
            pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
        }
        if (SUCCEEDED(pfd->Show(NULL)))
        {
            IShellItem *psi;
            if (SUCCEEDED(pfd->GetResult(&psi)))
            {
                if(!SUCCEEDED(psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &g_path)))
                {
                    MessageBox(NULL, "GetIDListName() failed", NULL, NULL);
                }
                psi->Release();
            }
        }
        pfd->Release();
    }
}
like image 484
Grizz Avatar asked Nov 25 '11 13:11

Grizz


1 Answers

Once you opt for FOS_PICKFOLDERS then you can't see files in the dialog, only folders. If you omit FOS_PICKFOLDERS then you can't select folders, only files. The standard dialog does not support what you are asking. You could write you own dialog but I'd be inclined to find a way to organise your application to fit around the behaviour of the standard dialog.

like image 50
David Heffernan Avatar answered Oct 26 '22 20:10

David Heffernan