我正在尝试使用IFileDialog来选择一个文件夹,以下代码就可以了。问题是我想在浏览时看到某些文件类型和文件夹(例如* .txt)。有一个简单的方法吗?
//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();
}
}