本文整理汇总了C++中IFileDialog::GetResult方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileDialog::GetResult方法的具体用法?C++ IFileDialog::GetResult怎么用?C++ IFileDialog::GetResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileDialog
的用法示例。
在下文中一共展示了IFileDialog::GetResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOpenDirectory
bool getOpenDirectory(char* out, int max_size, const char* starting_dir)
{
bool ret = false;
IFileDialog* pfd;
if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
{
if (starting_dir)
{
PIDLIST_ABSOLUTE pidl;
WCHAR wstarting_dir[MAX_PATH];
WCHAR* wc = wstarting_dir;
for (const char *c = starting_dir; *c && wc - wstarting_dir < MAX_PATH - 1; ++c, ++wc)
{
*wc = *c == '/' ? '\\' : *c;
}
*wc = 0;
HRESULT hresult = ::SHParseDisplayName(wstarting_dir, 0, &pidl, SFGAO_FOLDER, 0);
if (SUCCEEDED(hresult))
{
IShellItem* psi;
hresult = ::SHCreateShellItem(NULL, NULL, pidl, &psi);
if (SUCCEEDED(hresult))
{
pfd->SetFolder(psi);
}
ILFree(pidl);
}
}
DWORD dwOptions;
if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
{
pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
}
if (SUCCEEDED(pfd->Show(NULL)))
{
IShellItem* psi;
if (SUCCEEDED(pfd->GetResult(&psi)))
{
WCHAR* tmp;
if (SUCCEEDED(psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &tmp)))
{
char* c = out;
while (*tmp && c - out < max_size - 1)
{
*c = (char)*tmp;
++c;
++tmp;
}
*c = '\0';
ret = true;
}
psi->Release();
}
}
pfd->Release();
}
return ret;
}
示例2: PickContainer
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)))
{
PWSTR pszPath;
if (SUCCEEDED(GetIDListName(psi, &pszPath)))
{
MessageBox(NULL, pszPath, L"Selected Container", MB_OK);
CoTaskMemFree(pszPath);
}
psi->Release();
}
}
pfd->Release();
}
}
示例3: CoCreateInstance
char *commonItemDialog(HWND parent, REFCLSID clsid, REFIID iid, FILEOPENDIALOGOPTIONS optsadd)
{
IFileDialog *d = NULL;
FILEOPENDIALOGOPTIONS opts;
IShellItem *result = NULL;
WCHAR *wname = NULL;
char *name = NULL;
HRESULT hr;
hr = CoCreateInstance(clsid,
NULL, CLSCTX_INPROC_SERVER,
iid, (LPVOID *) (&d));
if (hr != S_OK) {
logHRESULT(L"error creating common item dialog", hr);
// always return NULL on error
goto out;
}
hr = d->GetOptions(&opts);
if (hr != S_OK) {
logHRESULT(L"error getting current options", hr);
goto out;
}
opts |= optsadd;
// the other platforms don't check read-only; we won't either
opts &= ~FOS_NOREADONLYRETURN;
hr = d->SetOptions(opts);
if (hr != S_OK) {
logHRESULT(L"error setting options", hr);
goto out;
}
hr = d->Show(parent);
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
// cancelled; return NULL like we have ready
goto out;
if (hr != S_OK) {
logHRESULT(L"error showing dialog", hr);
goto out;
}
hr = d->GetResult(&result);
if (hr != S_OK) {
logHRESULT(L"error getting dialog result", hr);
goto out;
}
hr = result->GetDisplayName(SIGDN_FILESYSPATH, &wname);
if (hr != S_OK) {
logHRESULT(L"error getting filename", hr);
goto out;
}
name = toUTF8(wname);
out:
if (wname != NULL)
CoTaskMemFree(wname);
if (result != NULL)
result->Release();
if (d != NULL)
d->Release();
return name;
}
示例4:
bool Gwen::Platform::FolderOpen( const String& Name, const String& StartPath, Gwen::Event::Handler* pHandler, Event::Handler::FunctionWithInformation fnCallback )
{
IFileDialog *pfd = NULL;
bool bSuccess = false;
if ( CoCreateInstance( CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS( &pfd ) ) != S_OK )
return bSuccess;
DWORD dwOptions;
if ( pfd->GetOptions(&dwOptions) != S_OK )
{
pfd->Release();
return bSuccess;
}
pfd->SetOptions( dwOptions | FOS_PICKFOLDERS );
//
// TODO: SetDefaultFolder -> StartPath
//
if ( pfd->Show(NULL) == S_OK )
{
IShellItem *psi;
if ( pfd->GetResult(&psi) == S_OK )
{
WCHAR* strOut = NULL;
if ( psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &strOut ) != S_OK )
{
return bSuccess;
}
//
// GWEN callback - call it.
//
if ( pHandler && fnCallback )
{
Gwen::Event::Information info;
info.Control = NULL;
info.ControlCaller = NULL;
info.String = Gwen::Utility::UnicodeToString( strOut );
(pHandler->*fnCallback)( info );
}
CoTaskMemFree( strOut );
psi->Release();
bSuccess = true;
}
}
pfd->Release();
return bSuccess;
}
示例5: openFile
static void openFile(HWND hWnd)
{
HRESULT hr;
IFileDialog *pFileDialog = nullptr;
IShellItem *pShellItem = nullptr;
PWSTR pFilePath = nullptr;
DWORD dwFlags;
/* Create FileOpenDialog */
hr = CoCreateInstance(CLSID_FileOpenDialog, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog));
if (FAILED(hr))
goto FINISH;
/* Get options */
hr = pFileDialog->GetOptions(&dwFlags);
if (FAILED(hr))
goto FINISH;
/* Get shell items only for file system items */
hr = pFileDialog->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
if (FAILED(hr))
goto FINISH;
/* Set file types */
COMDLG_FILTERSPEC fileTypes[] =
{
{ L"All supported images", L"*.png;*.jpg;*.jpeg;*.psd" },
};
hr = pFileDialog->SetFileTypes(ARRAYSIZE(fileTypes), fileTypes);
if (FAILED(hr))
goto FINISH;
/* Show dialog */
hr = pFileDialog->Show(hWnd);
if (FAILED(hr))
goto FINISH;
hr = pFileDialog->GetResult(&pShellItem);
if (FAILED(hr))
goto FINISH;
hr = pShellItem->GetDisplayName(SIGDN_FILESYSPATH, &pFilePath);
if (FAILED(hr))
goto FINISH;
loadImage(hWnd, pFilePath);
FINISH:
if (pFilePath)
CoTaskMemFree(pFilePath);
if (pShellItem)
pShellItem->Release();
if (pFileDialog)
pFileDialog->Release();
}
示例6: OnFileOpen
void OnFileOpen(HWND hwnd)
{
HRESULT hr = S_OK;
IFileDialog *pDialog = NULL;
IShellItem *pItem = NULL;
LPWSTR pwszFilePath = NULL;
// Create the FileOpenDialog object.
hr = CoCreateInstance(
__uuidof(FileOpenDialog),
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pDialog)
);
if (FAILED(hr)) { goto done; }
hr = pDialog->SetTitle(L"Select a File to Play");
if (FAILED(hr)) { goto done; }
// Show the file-open dialog.
hr = pDialog->Show(hwnd);
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
{
// User cancelled.
hr = S_OK;
goto done;
}
if (FAILED(hr)) { goto done; }
hr = pDialog->GetResult(&pItem);
if (FAILED(hr)) { goto done; }
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwszFilePath);
if (FAILED(hr)) { goto done; }
// Open the file and create bitmaps.
hr = OpenVideoFile(hwnd, pwszFilePath);
done:
if (FAILED(hr))
{
ShowErrorMessage(L"Cannot open file.", hr);
}
CoTaskMemFree(pwszFilePath);
SafeRelease(&pItem);
SafeRelease(&pDialog);
}
示例7: OnCommand
void OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch (id) {
case ID_FILE_OPEN:
{
IFileDialog *pFileDialog = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog));
if (SUCCEEDED(hr)) {
COMDLG_FILTERSPEC filter[3];
filter[0].pszName = L"位图文件(*.bmp)";
filter[0].pszSpec = L"*.bmp";
filter[1].pszName = L"JPEG(*.jpg;*.jpeg)";
filter[1].pszSpec = L"*.jpg;*.jpeg";
filter[2].pszName = L"所有支持的文件(*.jpg;*.jpeg;*.bmp;*.png)";
filter[2].pszSpec = L"*.jpg;*.jpeg;*.bmp;*.png";
hr = pFileDialog->SetFileTypes(3, filter);
hr = pFileDialog->SetFileTypeIndex(3);
hr = pFileDialog->Show(hwnd);
if (SUCCEEDED(hr)) {
IShellItem *psi = NULL;
hr = pFileDialog->GetResult(&psi);
if (SUCCEEDED(hr)) {
PWSTR pwszFilePath = NULL;
hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pwszFilePath);
if (SUCCEEDED(hr)) {
wchar_t * pext = wcsrchr(pwszFilePath, L'.');
if(pext != NULL && _wcsicmp(pext, L".bmp") == 0)
SendMessage(hwnd, WM_USER_IMG, 0, (LPARAM)pwszFilePath);
else
SendMessage(hwnd, WM_USER_IMG, 1, (LPARAM)pwszFilePath);
CoTaskMemFree(pwszFilePath);
}
psi->Release();
}
}
}
pFileDialog->Release();
break;
}
case ID_FILE_EXIT:
PostQuitMessage(0);
break;
default:
FORWARD_WM_COMMAND(hwnd, id, hwndCtl, codeNotify, DefWindowProc);
}
}
示例8: PickItem
void PickItem()
{
IFileDialog *pfd;
if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
{
if (SUCCEEDED(pfd->Show(NULL)))
{
IShellItem *psi;
if (SUCCEEDED(pfd->GetResult(&psi)))
{
PWSTR pszPath;
if (SUCCEEDED(GetIDListName(psi, &pszPath)))
{
MessageBox(NULL, pszPath, L"Selected Item", MB_OK);
CoTaskMemFree(pszPath);
}
psi->Release();
}
}
pfd->Release();
}
}
示例9: getOpenDirectory
bool getOpenDirectory(char* out, int max_size)
{
bool ret = false;
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)))
{
WCHAR* tmp;
if (SUCCEEDED(psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &tmp)))
{
char* c = out;
while (*tmp && c - out < max_size - 1)
{
*c = (char)*tmp;
++c;
++tmp;
}
*c = '\0';
ret = true;
}
psi->Release();
}
}
pfd->Release();
}
return ret;
}
示例10: ShowOpenDirectoryDialog
String ShowOpenDirectoryDialog()
{
String ret;
bool pathSelected = false;
// check current OS version
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osvi) && (osvi.dwMajorVersion >= 6))
{
// for Vista or later, use the MSDN-preferred implementation of the Open File dialog in pick folders mode
IFileDialog *pfd;
if (SUCCEEDED(CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd))))
{
// configure the dialog to Select Folders only
DWORD dwOptions;
if (SUCCEEDED(pfd->GetOptions(&dwOptions)))
{
pfd->SetOptions(dwOptions | FOS_PICKFOLDERS | FOS_DONTADDTORECENT);
if (SUCCEEDED(pfd->Show(GetActiveWindow())))
{
IShellItem *psi;
if (SUCCEEDED(pfd->GetResult(&psi)))
{
LPWSTR lpwszName = NULL;
if (SUCCEEDED(psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, (LPWSTR*) &lpwszName)))
{
// Add directory path to the result
//ConvertToUnixPath(pathName);
ret = lpwszName;
pathSelected = true;
::CoTaskMemFree(lpwszName);
}
psi->Release();
}
}
}
pfd->Release();
}
}
else
{
// for XP, use the old-styled SHBrowseForFolder() implementation
BROWSEINFO bi = {0};
bi.hwndOwner = GetActiveWindow();
bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if (pidl != 0)
{
TCHAR szFile[MAX_PATH];
szFile[0] = 0;
if (SHGetPathFromIDList(pidl, szFile))
{
// Add directory path to the result
//ConvertToUnixPath(pathName);
ret = szFile;
pathSelected = true;
}
IMalloc* pMalloc = NULL;
SHGetMalloc(&pMalloc);
if (pMalloc)
{
pMalloc->Free(pidl);
pMalloc->Release();
}
}
}
return ret;
}
示例11: load_file
/*
ANT_CANVAS::LOAD_FILE()
-----------------------
*/
long long ANT_canvas::load_file(void)
{
long long lines;
IFileDialog *pfd = NULL;
IShellItem *psiResult;
DWORD dwFlags;
PWSTR pszFilePath = NULL;
char chosen_filter[1024];
char chosen_filename[MAX_PATH];
OPENFILENAME parameters;
/*
Create the Open Dialg object IFileDialog
*/
if ((CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd)) == S_OK))
{
/*
we're on VISTA / Windows 7 or later
*/
const COMDLG_FILTERSPEC c_rgSaveTypes[] =
{
{L"C/C++ files", L"*.c;*.cxx;*.cpp;*.h;*.hpp.*.hxx;*.mak;makefile"},
{L"All Documents (*.*)", L"*.*"}
};
pfd->GetOptions(&dwFlags);
pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM); // we want to see a file
pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
pfd->SetFileTypeIndex(1); // first item in the list is the default
pfd->SetDefaultExtension(L"doc;docx");
if (pfd->Show(NULL) == S_OK)
{
if (pfd->GetResult(&psiResult) == S_OK) // get the result object if the user clicks "Open"
{
psiResult->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
lines = file->read_file((char *)pszFilePath);
CoTaskMemFree(pszFilePath);
psiResult->Release();
}
}
pfd->Release();
return lines;
}
else
{
/*
we're on something prior to VISTA (NT through to XP) so use the old-style common control
*/
memset(chosen_filename, 0, sizeof(chosen_filename));
parameters.lStructSize = sizeof(parameters);
parameters.hwndOwner = window;
parameters.hInstance = hInstance;
parameters.lpstrFilter = L"C/C++ files\0*.c;*.cxx;*.cpp;*.h;*.hpp.*.hxx\0\0\0";
parameters.lpstrCustomFilter = (LPWSTR)chosen_filter;
parameters.nMaxCustFilter = sizeof(chosen_filter) - 1;
parameters.nFilterIndex = 1;
parameters.lpstrFile = (LPWSTR)chosen_filename;
parameters.nMaxFile = sizeof(chosen_filename) - 1;
parameters.lpstrFileTitle = NULL;
parameters.nMaxFileTitle = 0;
parameters.lpstrInitialDir = NULL;
parameters.lpstrTitle = L"Open...";
parameters.Flags = OFN_LONGNAMES;
parameters.nFileOffset = 0;
parameters.nFileExtension = 0;
parameters.lpstrDefExt = NULL;
parameters.lCustData = 0;
parameters.lpfnHook = NULL;
parameters.lpTemplateName = 0;
#if (_WIN32_WINNT >= 0x0500)
parameters.pvReserved = NULL;
parameters.dwReserved = 0;
parameters.FlagsEx = 0;
#endif
if ((GetOpenFileNameW(¶meters)) != 0)
return file->read_file((char *)parameters.lpstrFile);
}
return 0;
}
示例12: OpenCommonFileDialogTo
// This opens up the common file dialog to an IShellItem and waits for the user to select a file from the results.
// It then displays the name of the selected item in a message box.
HRESULT OpenCommonFileDialogTo(IShellItem *pShellItemSearch)
{
// Create an instance of IFileOpenDialog
IFileDialog* pFileDialog;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog));
if (SUCCEEDED(hr))
{
// Set it to the folder we want to show
hr = pFileDialog->SetFolder(pShellItemSearch);
if (SUCCEEDED(hr))
{
// Show the File Dialog
hr = pFileDialog->Show(NULL);
if (SUCCEEDED(hr))
{
// Now get the file that the user selected
IShellItem *pShellItemSelected;
hr = pFileDialog->GetResult(&pShellItemSelected);
if (SUCCEEDED(hr))
{
// Get the name from that file
PWSTR pszName;
hr = pShellItemSelected->GetDisplayName(SIGDN_NORMALDISPLAY, &pszName);
if (SUCCEEDED(hr))
{
// Display it back to the user
WCHAR szMsg[128];
StringCchPrintf(szMsg, ARRAYSIZE(szMsg), L"You Chose '%s'\r", pszName);
MessageBox(NULL, szMsg, L"Search Folder Sample", MB_OK);
CoTaskMemFree(pszName);
}
pShellItemSelected->Release();
}
}
}
pFileDialog->Release();
}
return hr;
}
示例13: get_directory
string get_directory(string dname, string caption)
{
//NOTE: This uses the Windows Vista or later file chooser, which is different than the one used by GM8 and lower
//because I could not find out which one it uses, since IFileDialog is used by both wxWidgets and QtFramework
//and there doesn't appear to be a standard file picker for XP or lower in the Windows API except SHBrowseForFolder that is
//used by Game Maker for get_directory_alt
IFileDialog* fileDialog;
CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&fileDialog));
DWORD options;
fileDialog->GetOptions(&options);
options &= ~FOS_FILEMUSTEXIST;
options &= ~FOS_PATHMUSTEXIST;
fileDialog->SetOptions(options | FOS_PICKFOLDERS);
//TODO: Set default directory to dname
fileDialog->SetTitle(std::wstring(caption.begin(), caption.end()).c_str());
fileDialog->Show(enigma::hWnd);
string res = "";
IShellItem *psi;
if (SUCCEEDED(fileDialog->GetResult(&psi))) {
LPWSTR wideres;
psi->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &wideres);
psi->Release();
//TODO: Fuck Microsoft with a wooden spoon
std::wstring wtf = wideres;
res = string(wtf.begin(), wtf.end());
}
return res;
}
示例14: openBrowseDialogCore
void openBrowseDialogCore(FileDialogType type, const Path& defaultPath, const String& filterList,
Vector<Path>& paths, AsyncOp& returnValue)
{
// Init COM library.
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
IFileDialog* fileDialog = nullptr;
UINT32 dialogType = ((UINT32)type & (UINT32)FileDialogType::TypeMask);
bool isOpenDialog = dialogType == (UINT32)FileDialogType::OpenFile || dialogType == (UINT32)FileDialogType::OpenFolder;
// Create dialog
IID classId = isOpenDialog ? CLSID_FileOpenDialog : CLSID_FileSaveDialog;
CoCreateInstance(classId, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&fileDialog));
addFiltersToDialog(fileDialog, filterList);
setDefaultPath(fileDialog, defaultPath);
// Apply multiselect flags
bool isMultiselect = false;
if (isOpenDialog)
{
if (dialogType == (UINT32)FileDialogType::OpenFile)
{
if (((UINT32)type & (UINT32)FileDialogType::Multiselect) != 0)
{
DWORD dwFlags;
fileDialog->GetOptions(&dwFlags);
fileDialog->SetOptions(dwFlags | FOS_ALLOWMULTISELECT);
isMultiselect = true;
}
}
else
{
DWORD dwFlags;
fileDialog->GetOptions(&dwFlags);
fileDialog->SetOptions(dwFlags | FOS_PICKFOLDERS);
}
}
// Show the dialog
bool finalResult = false;
// Need to enable all windows, otherwise when the browse dialog closes the active window will become some
// background window
Win32Window::_enableAllWindows();
if (SUCCEEDED(fileDialog->Show(nullptr)))
{
if (isMultiselect)
{
// Get file names
IFileOpenDialog* fileOpenDialog;
fileDialog->QueryInterface(IID_IFileOpenDialog, (void**)&fileOpenDialog);
IShellItemArray* shellItems = nullptr;
fileOpenDialog->GetResults(&shellItems);
getPaths(shellItems, paths);
shellItems->Release();
fileOpenDialog->Release();
}
else
{
// Get the file name
IShellItem* shellItem = nullptr;
fileDialog->GetResult(&shellItem);
LPWSTR filePath = nullptr;
shellItem->GetDisplayName(SIGDN_FILESYSPATH, &filePath);
paths.push_back((Path)UTF8::fromWide(WString(filePath)));
CoTaskMemFree(filePath);
shellItem->Release();
}
finalResult = true;
}
// Restore modal window state (before we enabled all windows)
Win32Window::_restoreModalWindows();
CoUninitialize();
returnValue._completeOperation(finalResult);
}
示例15: runModalInternal
//-----------------------------------------------------------------------------
bool VistaFileSelector::runModalInternal ()
{
fileDialog = 0;
HRESULT hr = -1;
if (style == kSelectSaveFile)
{
hr = CoCreateInstance (CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IFileDialog, &fileDialog));
if (defaultSaveName)
{
fileDialog->SetFileName (UTF8StringHelper (defaultSaveName));
}
}
else
{
hr = CoCreateInstance (CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IFileDialog, &fileDialog));
if (SUCCEEDED (hr))
{
if (style == kSelectDirectory)
{
DWORD dwOptions = 0;
hr = fileDialog->GetOptions (&dwOptions);
if (SUCCEEDED (hr))
hr = fileDialog->SetOptions (dwOptions | FOS_PICKFOLDERS);
if (FAILED (hr))
{
fileDialog->Release ();
fileDialog = 0;
return false;
}
}
if (allowMultiFileSelection)
{
DWORD dwOptions = 0;
hr = fileDialog->GetOptions (&dwOptions);
if (SUCCEEDED (hr))
hr = fileDialog->SetOptions (dwOptions | FOS_ALLOWMULTISELECT);
if (FAILED (hr))
{
fileDialog->Release ();
fileDialog = 0;
return false;
}
}
}
}
if (FAILED (hr))
{
fileDialog = 0;
return false;
}
if (title)
hr = fileDialog->SetTitle (UTF8StringHelper (title));
DWORD numExtensions = 0;
DWORD defaultFileTypeIndex = 0;
COMDLG_FILTERSPEC* filters = buildExtensionFilter (extensions, defaultExtension, numExtensions, defaultFileTypeIndex);
if (filters)
{
fileDialog->SetFileTypes (numExtensions, filters);
if (defaultFileTypeIndex)
fileDialog->SetFileTypeIndex (defaultFileTypeIndex);
}
if (initialPath && _SHCreateItemFromParsingName)
{
IShellItem* shellItem;
hr = _SHCreateItemFromParsingName (UTF8StringHelper (initialPath), 0, IID_PPV_ARG (IShellItem, &shellItem));
if (SUCCEEDED (hr))
{
fileDialog->SetFolder (shellItem);
shellItem->Release ();
}
}
Win32Frame* win32Frame = frame->getPlatformFrame () ? dynamic_cast<Win32Frame*> (frame->getPlatformFrame ()) : 0;
hr = fileDialog->Show (win32Frame ? win32Frame->getPlatformWindow () : 0);
if (SUCCEEDED (hr))
{
if (allowMultiFileSelection)
{
IFileOpenDialog* openFileDialog = 0;
hr = fileDialog->QueryInterface (IID_PPV_ARG(IFileOpenDialog, &openFileDialog));
if (SUCCEEDED (hr))
{
IShellItemArray* items;
hr = openFileDialog->GetResults (&items);
if (SUCCEEDED (hr))
{
DWORD count;
hr = items->GetCount (&count);
for (DWORD i = 0; i < count; i++)
{
IShellItem* item;
hr = items->GetItemAt (i, &item);
if (SUCCEEDED (hr))
{
LPWSTR filesysPath = 0;
hr = item->GetDisplayName (SIGDN_FILESYSPATH, &filesysPath);
if (SUCCEEDED (hr))
{
//.........这里部分代码省略.........