本文整理汇总了C++中IFileOpenDialog::GetFolder方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileOpenDialog::GetFolder方法的具体用法?C++ IFileOpenDialog::GetFolder怎么用?C++ IFileOpenDialog::GetFolder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileOpenDialog
的用法示例。
在下文中一共展示了IFileOpenDialog::GetFolder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qt_win_CID_get_open_file_names
QStringList qt_win_CID_get_open_file_names(const QFileDialogArgs &args,
QString *initialDirectory,
const QStringList &filterList,
QString *selectedFilter,
int selectedFilterIndex)
{
QStringList result;
QDialog modal_widget;
modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
modal_widget.setParent(args.parent, Qt::Window);
QApplicationPrivate::enterModal(&modal_widget);
// Multiple selection is allowed only in IFileOpenDialog.
IFileOpenDialog *pfd = 0;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr)) {
qt_win_set_IFileDialogOptions(pfd, args.selection,
args.directory, args.caption,
filterList, QFileDialog::ExistingFiles,
args.options);
// Set the currently selected filter (one-based index).
hr = pfd->SetFileTypeIndex(selectedFilterIndex+1);
QWidget *parentWindow = args.parent;
if (parentWindow)
parentWindow = parentWindow->window();
else
parentWindow = QApplication::activeWindow();
// Show the file dialog.
hr = pfd->Show(parentWindow ? parentWindow->winId() : 0);
if (SUCCEEDED(hr)) {
// Retrieve the results.
IShellItemArray *psiaResults;
hr = pfd->GetResults(&psiaResults);
if (SUCCEEDED(hr)) {
DWORD numItems = 0;
psiaResults->GetCount(&numItems);
for (DWORD i = 0; i<numItems; i++) {
IShellItem *psi = 0;
hr = psiaResults->GetItemAt(i, &psi);
if (SUCCEEDED(hr)) {
// Retrieve the file name from shell item.
wchar_t *pszPath;
hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
if (SUCCEEDED(hr)) {
QString fileName = QString::fromWCharArray(pszPath);
result.append(fileName);
CoTaskMemFree(pszPath);
}
psi->Release(); // Free the current item.
}
}
psiaResults->Release(); // Free the array of items.
}
}
}
QApplicationPrivate::leaveModal(&modal_widget);
qt_win_eatMouseMove();
if (!result.isEmpty()) {
// Retrieve the current folder name.
IShellItem *psi = 0;
hr = pfd->GetFolder(&psi);
if (SUCCEEDED(hr)) {
wchar_t *pszPath;
hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
if (SUCCEEDED(hr)) {
*initialDirectory = QString::fromWCharArray(pszPath);
CoTaskMemFree(pszPath);
}
psi->Release();
}
// Retrieve the currently selected filter.
if (selectedFilter) {
quint32 filetype = 0;
hr = pfd->GetFileTypeIndex(&filetype);
if (SUCCEEDED(hr) && filetype && filetype <= (quint32)filterList.length()) {
// This is a one-based index, not zero-based.
*selectedFilter = filterList[filetype-1];
}
}
}
if (pfd)
pfd->Release();
return result;
}