本文整理汇总了C++中IFileDialog::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileDialog::Release方法的具体用法?C++ IFileDialog::Release怎么用?C++ IFileDialog::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileDialog
的用法示例。
在下文中一共展示了IFileDialog::Release方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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;
}
示例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: 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;
}
示例4: 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;
}
示例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: 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();
}
}
示例7: 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;
}
示例8: 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);
}
}
示例9: 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;
}
示例10: 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;
}
示例11: 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();
}
}
示例12: 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;
}
示例13: LoadFile
void prefs_file::LoadFile(int filename_id, int metadata_id,
int level_id, int enable_id)
{
COMDLG_FILTERSPEC c_rgSaveTypes[] =
{
{ _T("Audio Files"), L"*.aiff;*.au;*.caf;*.flac;*.iff;*.mat;*.nist;*.ogg;*.paf;*.rf64;*.sf;*.snd;*.sph;*.svx;*.voc;*.w64;*.wav" },
{ _T("All Files"), L"*.*"}
};
// CoCreate the File Open Dialog object.
IFileDialog *pfd = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Set the file types to display only.
// Notice that this is a 1-based array.
hr = pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(NULL);
if (SUCCEEDED(hr))
{
// Obtain the result once the user clicks
// the 'Open' button.
// The result is an IShellItem object.
IShellItem *psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath = NULL;
hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH,
&pszFilePath);
if (SUCCEEDED(hr))
{
int n_channels;
int n_frames;
int sampling_rate;
double attenuation;
// Calculate the optimum attentuation to prevent clipping
if (preprocessor::calculate_attenuation(pszFilePath,
FILTER_LEN,
REALSIZE,
&attenuation,
&n_channels,
&n_frames,
&sampling_rate))
{
SetDlgItemText(filename_id, pszFilePath);
std::wstringstream info;
info << n_frames << L" samples, "
<< n_channels << L" channels, "
<< sampling_rate << L" Hz";
SetDlgItemText(metadata_id, info.str().c_str());
CTrackBarCtrl slider = GetDlgItem(IDC_SLIDER_LEVEL1);
slider.SetPos((int)(attenuation * FILE_LEVEL_STEPS_PER_DB));
CheckDlgButton(enable_id, 1);
RefreshFileLevelLabel();
}
CoTaskMemFree(pszFilePath);
}
psiResult->Release();
}
}
}
}
pfd->Release();
}
示例14: 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;
}
示例15: BasicFileOpen
HRESULT BasicFileOpen(PWSTR* filePath)
{
// CoCreate the File Open Dialog object.
IFileDialog *pfd = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr))
{
// Create an event handling object, and hook it up to the dialog.
IFileDialogEvents *pfde = NULL;
//DWORD dwCookie;
// Set the options on the dialog.
DWORD dwFlags;
// Before setting, always get the options first in order
// not to override existing options.
hr = pfd->GetOptions(&dwFlags);
if (SUCCEEDED(hr))
{
// In this case, get shell items only for file system items.
hr = pfd->SetOptions(dwFlags | FOS_FORCEFILESYSTEM);
if (SUCCEEDED(hr))
{
static const COMDLG_FILTERSPEC c_rgSaveTypes[] =
{
{L"Executable Files(*.exe)", L"*.exe"},
};
// Set the file types to display only.
// Notice that this is a 1-based array.
hr = pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
if (SUCCEEDED(hr))
{
// Set the selected file type index to Word Docs for this example.
hr = pfd->SetFileTypeIndex(1);
if (SUCCEEDED(hr))
{
// Set the default extension to be ".doc" file.
hr = pfd->SetDefaultExtension(L"exe");
if (SUCCEEDED(hr))
{
// Show the dialog
hr = pfd->Show(g_hwnd);
if (SUCCEEDED(hr))
{
// Obtain the result once the user clicks
// the 'Open' button.
// The result is an IShellItem object.
IShellItem *psiResult;
hr = pfd->GetResult(&psiResult);
if (SUCCEEDED(hr))
{
// We are just going to print out the
// name of the file for sample sake.
PWSTR pszFilePath = NULL;
hr = psiResult->GetDisplayName(SIGDN_FILESYSPATH,
&pszFilePath);
if (SUCCEEDED(hr))
{
*filePath=pszFilePath;
}
psiResult->Release();
}
}
}
}
}
}
}
pfd->Release();
}
else
{
hr=E_OUTOFMEMORY;
OPENFILENAME ofn;
LPWSTR pszFile=(LPWSTR)CoTaskMemAlloc(260*2);
if(pszFile!=NULL)
{
memset1(&ofn,0,sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = g_hwnd;
ofn.lpstrFile = pszFile;
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
ofn.lpstrFile[0] = L'\0';
ofn.nMaxFile = 260;
ofn.lpstrFilter = L"Executable Files(*.exe)\0*.exe\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if (GetOpenFileName(&ofn)==TRUE)
{
*filePath=pszFile;
hr=0;
}
//.........这里部分代码省略.........