本文整理汇总了C++中IFileOpenDialog::QueryInterface方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileOpenDialog::QueryInterface方法的具体用法?C++ IFileOpenDialog::QueryInterface怎么用?C++ IFileOpenDialog::QueryInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileOpenDialog
的用法示例。
在下文中一共展示了IFileOpenDialog::QueryInterface方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Show
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
retVal ret = OK; //assume OK
m_sDefaultPath = sDefaultPath;
if (m_sDefaultPath.IsEmpty() && !path.IsEmpty())
{
// if the result path already contains a path, use that as the default path
m_sDefaultPath = path;
}
HRESULT hr;
// Create a new common open file dialog
IFileOpenDialog* pfd = NULL;
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Set the dialog as a folder picker
DWORD dwOptions;
if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions)))
{
hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
}
// Set a title
if (SUCCEEDED(hr))
{
TCHAR * nl = _tcschr(m_title, '\n');
if (nl)
*nl = 0;
pfd->SetTitle(m_title);
}
// set the default folder
if (SUCCEEDED(hr))
{
typedef HRESULT (WINAPI *SHCIFPN)(PCWSTR pszPath, IBindCtx * pbc, REFIID riid, void ** ppv);
CAutoLibrary hLib = AtlLoadSystemLibraryUsingFullPath(L"shell32.dll");
if (hLib)
{
SHCIFPN pSHCIFPN = (SHCIFPN)GetProcAddress(hLib, "SHCreateItemFromParsingName");
if (pSHCIFPN)
{
IShellItem *psiDefault = 0;
hr = pSHCIFPN(m_sDefaultPath, NULL, IID_PPV_ARGS(&psiDefault));
if (SUCCEEDED(hr))
{
hr = pfd->SetFolder(psiDefault);
psiDefault->Release();
}
}
}
}
if (m_CheckText[0] != 0)
{
IFileDialogCustomize* pfdCustomize = 0;
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
if (SUCCEEDED(hr))
{
pfdCustomize->StartVisualGroup(100, L"");
pfdCustomize->AddCheckButton(101, m_CheckText, FALSE);
if (m_CheckText2[0] != 0)
{
pfdCustomize->AddCheckButton(102, m_CheckText2, FALSE);
}
pfdCustomize->EndVisualGroup();
pfdCustomize->Release();
}
}
// Show the open file dialog
if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(parent)))
{
// Get the selection from the user
IShellItem* psiResult = NULL;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
PWSTR pszPath = NULL;
hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
if (SUCCEEDED(hr))
{
path = pszPath;
CoTaskMemFree(pszPath);
}
psiResult->Release();
IFileDialogCustomize* pfdCustomize = 0;
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
if (SUCCEEDED(hr))
{
pfdCustomize->GetCheckButtonState(101, &m_bCheck);
pfdCustomize->GetCheckButtonState(102, &m_bCheck2);
pfdCustomize->Release();
}
}
else
ret = CANCEL;
//.........这里部分代码省略.........
示例2: OpenFilesVistaUp
BOOL OpenFilesVistaUp(HWND hwnd, lFILEINFO *pFInfoList)
{
IFileOpenDialog *pfd;
IFileDialogCustomize *pfdc;
FILEOPENDIALOGOPTIONS dwOptions;
DWORD dwCookie = 0;
CoInitialize(NULL);
// CoCreate the dialog object.
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr)) {
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdc));
if(SUCCEEDED(hr)) {
hr = pfdc->EnableOpenDropDown(FDIALOG_OPENCHOICES);
if (SUCCEEDED(hr))
{
hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES, FDIALOG_CHOICE_OPEN, L"&Open");
if (SUCCEEDED(hr))
{
hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES,
FDIALOG_CHOICE_REPARENT,
L"&Reparent hash file");
hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES,
FDIALOG_CHOICE_ALLHASHES,
L"&Open all hash files");
hr = pfdc->AddControlItem(FDIALOG_OPENCHOICES,
FDIALOG_CHOICE_BSD,
L"&Force open as BSD-style");
}
}
}
pfdc->Release();
hr = pfd->GetOptions(&dwOptions);
if (SUCCEEDED(hr)) {
hr = pfd->SetOptions(dwOptions | FOS_ALLOWMULTISELECT | FOS_FORCEFILESYSTEM);
if (SUCCEEDED(hr)) {
COpenFileListener *ofl = new COpenFileListener(pFInfoList);
hr = pfd->Advise(ofl,&dwCookie);
if (SUCCEEDED(hr)) {
hr = pfd->Show(hwnd);
if (SUCCEEDED(hr)) {
}
pfd->Unadvise(dwCookie);
}
}
}
pfd->Release();
}
CoUninitialize();
return SUCCEEDED(hr);
}
示例3: Show
CBrowseFolder::retVal CBrowseFolder::Show(HWND parent, CString& path, const CString& sDefaultPath /* = CString() */)
{
retVal ret = OK; //assume OK
m_sDefaultPath = sDefaultPath;
if (m_sDefaultPath.IsEmpty() && !path.IsEmpty())
{
while (!PathFileExists(path) && !path.IsEmpty())
{
CString p = path.Left(path.ReverseFind('\\'));
if ((p.GetLength() == 2)&&(p[1] == ':'))
{
p += L"\\";
if (p.Compare(path) == 0)
p.Empty();
}
if (p.GetLength() < 2)
p.Empty();
path = p;
}
// if the result path already contains a path, use that as the default path
m_sDefaultPath = path;
}
HRESULT hr;
// Create a new common open file dialog
IFileOpenDialog* pfd = NULL;
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Set the dialog as a folder picker
DWORD dwOptions;
if (SUCCEEDED(hr = pfd->GetOptions(&dwOptions)))
{
hr = pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
}
// Set a title
if (SUCCEEDED(hr))
{
TCHAR * nl = wcschr(m_title, '\n');
if (nl)
*nl = 0;
pfd->SetTitle(m_title);
}
// set the default folder
if (SUCCEEDED(hr))
{
IShellItem *psiDefault = 0;
hr = SHCreateItemFromParsingName(m_sDefaultPath, NULL, IID_PPV_ARGS(&psiDefault));
if (SUCCEEDED(hr))
{
hr = pfd->SetFolder(psiDefault);
psiDefault->Release();
}
}
if (m_CheckText[0] != 0)
{
IFileDialogCustomize* pfdCustomize = 0;
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
if (SUCCEEDED(hr))
{
pfdCustomize->StartVisualGroup(100, L"");
pfdCustomize->AddCheckButton(101, m_CheckText, FALSE);
if (m_CheckText2[0] != 0)
{
pfdCustomize->AddCheckButton(102, m_CheckText2, FALSE);
}
pfdCustomize->EndVisualGroup();
pfdCustomize->Release();
}
}
// Show the open file dialog
if (SUCCEEDED(hr) && SUCCEEDED(hr = pfd->Show(parent)))
{
// Get the selection from the user
IShellItem* psiResult = NULL;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
PWSTR pszPath = NULL;
hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
if (SUCCEEDED(hr))
{
path = pszPath;
CoTaskMemFree(pszPath);
}
psiResult->Release();
IFileDialogCustomize* pfdCustomize = 0;
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdCustomize));
if (SUCCEEDED(hr))
{
pfdCustomize->GetCheckButtonState(101, &m_bCheck);
pfdCustomize->GetCheckButtonState(102, &m_bCheck2);
pfdCustomize->Release();
}
//.........这里部分代码省略.........