Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
890 views
in Technique[技术] by (71.8m points)

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

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();
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...