本文整理汇总了C++中IFileDialog类的典型用法代码示例。如果您正苦于以下问题:C++ IFileDialog类的具体用法?C++ IFileDialog怎么用?C++ IFileDialog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IFileDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: DeletePerUserDialogState
void DeletePerUserDialogState()
{
IFileDialog *pfd;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Delete window size, MRU and other saved data for testing initial case
pfd->ClearClientData();
pfd->Release();
}
}
示例3: OnButtonClicked
IFACEMETHODIMP OnButtonClicked(IFileDialogCustomize *fdc, DWORD idCtl) {
DBGW(L"OnButtonClicked\n");
if (idCtl == ID_SELECT) {
IFileDialog *fd = NULL;
if (SUCCEEDED(fdc->QueryInterface(&fd))) {
if (GetSelectedItems(fd, res) && res->size()) {
fd->Close(S_OK);
fd->Release();
}
}
}
return S_OK;
}
示例4: 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;
}
示例5: OnButtonClicked
IFACEMETHODIMP OnButtonClicked(IFileDialogCustomize *pfdc, DWORD dwIDCtl)
{
switch (dwIDCtl)
{
case c_idDone:
IFileDialog *pfd;
if (SUCCEEDED(pfdc->QueryInterface(&pfd)))
{
pfd->Close(S_OK);
pfd->Release();
}
break;
default:
break;
}
return S_OK;
}
示例6:
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;
}
示例7: 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();
}
示例8: 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();
}
}
示例9: 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;
}
示例10: 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();
}
}
示例11: 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;
}
示例12: 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);
}
}
示例13: 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;
}
示例14: 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;
}
示例15: 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);
}