本文整理汇总了C++中IFileOpenDialog类的典型用法代码示例。如果您正苦于以下问题:C++ IFileOpenDialog类的具体用法?C++ IFileOpenDialog怎么用?C++ IFileOpenDialog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IFileOpenDialog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFile
PWSTR LoadFile() {
IFileOpenDialog *pFileOpen;
PWSTR pszFilePath = NULL;
// Create the FileOpenDialog object.
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
//IShellItem *psiDocuments = NULL;
//hr = SHCreateItemInKnownFolder(FOLDERID_Documents, 0, NULL, IID_PPV_ARGS(&psiDocuments));
//if (SUCCEEDED(hr)) {
// hr = pFileOpen->SetFolder(psiDocuments);
// psiDocuments->Release();
//}
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
pItem->Release();
}
}
pFileOpen->Release();
}
return pszFilePath;
}
示例2: OnFileOpen
// Open an audio/video file.
void OnFileOpen(HWND hwnd)
{
IFileOpenDialog *pFileOpen = NULL;
IShellItem *pItem = NULL;
PWSTR pszFilePath = NULL;
// Create the FileOpenDialog object.
HRESULT hr = CoCreateInstance(__uuidof(FileOpenDialog), NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));
if (FAILED(hr))
{
goto done;
}
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
if (hr == HRESULT_FROM_WIN32(ERROR_CANCELLED))
{
// The user canceled the dialog. Do not treat as an error.
hr = S_OK;
goto done;
}
else if (FAILED(hr))
{
goto done;
}
// Get the file name from the dialog box.
hr = pFileOpen->GetResult(&pItem);
if (FAILED(hr))
{
goto done;
}
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (FAILED(hr))
{
goto done;
}
// Display the file name to the user.
hr = g_pPlayer->OpenURL(pszFilePath);
if (SUCCEEDED(hr))
{
UpdateUI(hwnd, OpenPending);
}
done:
if (FAILED(hr))
{
NotifyError(hwnd, L"Could not open the file.", hr);
UpdateUI(hwnd, Closed);
}
CoTaskMemFree(pszFilePath);
SafeRelease(&pItem);
SafeRelease(&pFileOpen);
}
示例3: OnFileOk
STDMETHODIMP COpenFileListener::OnFileOk(IFileDialog* pfd)
{
IShellItemArray *psiaResults;
IFileDialogCustomize *pfdc;
HRESULT hr;
IFileOpenDialog *fod;
FILEINFO fileinfoTmp = {0};
DWORD choice;
fileinfoTmp.parentList = pFInfoList;
hr = pfd->QueryInterface(IID_PPV_ARGS(&fod));
if(SUCCEEDED(hr)) {
hr = fod->GetSelectedItems(&psiaResults);
if (SUCCEEDED(hr)) {
DWORD fileCount;
IShellItem *isi;
LPWSTR pwsz = NULL;
psiaResults->GetCount(&fileCount);
for(DWORD i=0;i<fileCount;i++) {
psiaResults->GetItemAt(i,&isi);
isi->GetDisplayName(SIGDN_FILESYSPATH,&pwsz);
isi->Release();
fileinfoTmp.szFilename = pwsz;
pFInfoList->fInfos.push_back(fileinfoTmp);
CoTaskMemFree(pwsz);
}
psiaResults->Release();
}
fod->Release();
}
hr = pfd->QueryInterface(IID_PPV_ARGS(&pfdc));
if(SUCCEEDED(hr)) {
hr = pfdc->GetSelectedControlItem(FDIALOG_OPENCHOICES,&choice);
if(SUCCEEDED(hr)) {
if(choice==FDIALOG_CHOICE_REPARENT) {
pFInfoList->uiCmdOpts = CMD_REPARENT;
}
else if(choice==FDIALOG_CHOICE_ALLHASHES) {
pFInfoList->uiCmdOpts = CMD_ALLHASHES;
}
else if(choice==FDIALOG_CHOICE_BSD) {
pFInfoList->uiCmdOpts = CMD_FORCE_BSD;
}
}
pfdc->Release();
}
return S_OK;
}
示例4: CoInitializeEx
void FileOpen::showDialog()
{
#ifdef _WIN32
path = NULL;
HRESULT hResult = CoInitializeEx(NULL,
COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hResult))
{
//Create a instance to open the fileOpenDialog
IFileOpenDialog *pFileOpen;
hResult = CoCreateInstance(CLSID_FileOpenDialog, NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));
if (SUCCEEDED(hResult))
{
//show the File Open
hResult = pFileOpen->Show(NULL);
//get the file name result
if (SUCCEEDED(hResult))
{
IShellItem *pItem;
hResult = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hResult))
{
PWSTR FilePath;
hResult = pItem->GetDisplayName(SIGDN_FILESYSPATH, &FilePath);
//get the file name and copy to "path"
if (SUCCEEDED(hResult))
{
int count = wcslen(FilePath);
path = new char[2*count];
wcstombs(path, FilePath, count);
path[count] = '\0';
CoTaskMemFree(FilePath);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
#else
std::cout << "Sorry, this is not implemented on linux yet =(" << std::endl;
return;
#endif
}
示例5: ReadFromFile
BOOL ReadFromFile()
{
IFileOpenDialog *pDlg;
COMDLG_FILTERSPEC FileTypes[] = {
{ L"PS2 MemoryCard files", L"*.ps2" },
{ L"All files", L"*.*" }
};
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDlg));
WCHAR cPath[MAX_PATH] = L"";
GetCurrentDirectoryW(sizeof(cPath) / sizeof(cPath[0]), cPath);
IShellItem *psiFolder, *psiParent;
SHCreateItemFromParsingName(cPath, NULL, IID_PPV_ARGS(&psiFolder));
psiFolder->GetParent(&psiParent);
//初期フォルダの指定
pDlg->SetFolder(psiFolder);
//フィルターの指定
pDlg->SetFileTypes(_countof(FileTypes), FileTypes);
//ダイアログ表示
hr = pDlg->Show(NULL);
//ファイル名
LPOLESTR pwsz = NULL;
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pDlg->GetResult(&pItem);
if (SUCCEEDED(hr))
{
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pwsz);
if (SUCCEEDED(hr))
{
HANDLE hFile;
hFile = CreateFile(pwsz, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hFile)
{
DWORD BytesRead;
BOOL b = ReadFile(hFile, &(byteMemDat.Byte), sizeof(byteMemDat), &BytesRead, NULL);
if (BytesRead)
{
CloseHandle(hFile);
}
}
}
}
}
UpdateDataList(&byteMemDat);
return TRUE;
}
示例6: CoCreateInstance
std::vector<std::wstring> APlayerWindow::showOpenFile()
{
HRESULT hr = S_OK;
std::vector<std::wstring> filePaths;
IFileOpenDialog *fileDlg = NULL;
hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&fileDlg));
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { fileDlg->Release(); });
IKnownFolderManager *pkfm = NULL;
hr = CoCreateInstance(CLSID_KnownFolderManager,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pkfm));
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { pkfm->Release(); });
IKnownFolder *pKnownFolder = NULL;
hr = pkfm->GetFolder(FOLDERID_PublicMusic, &pKnownFolder);
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { pKnownFolder->Release(); });
IShellItem *psi = NULL;
hr = pKnownFolder->GetShellItem(0, IID_PPV_ARGS(&psi));
if (FAILED(hr)) return filePaths;
ON_SCOPE_EXIT([&] { psi->Release(); });
hr = fileDlg->AddPlace(psi, FDAP_BOTTOM);
COMDLG_FILTERSPEC rgSpec[] = {
{ L"ÒôÀÖÎļþ", SupportType }
};
fileDlg->SetFileTypes(1, rgSpec);
DWORD dwOptions;
fileDlg->GetOptions(&dwOptions);
fileDlg->SetOptions(dwOptions | FOS_ALLOWMULTISELECT);
hr = fileDlg->Show(NULL);
if (SUCCEEDED(hr)) {
IShellItemArray *pRets;
hr = fileDlg->GetResults(&pRets);
if (SUCCEEDED(hr)) {
DWORD count;
pRets->GetCount(&count);
for (DWORD i = 0; i < count; i++) {
IShellItem *pRet;
LPWSTR nameBuffer;
pRets->GetItemAt(i, &pRet);
pRet->GetDisplayName(SIGDN_DESKTOPABSOLUTEPARSING, &nameBuffer);
filePaths.push_back(std::wstring(nameBuffer));
pRet->Release();
CoTaskMemFree(nameBuffer);
}
pRets->Release();
}
}
return filePaths;
}
示例7: CoUninitialize
~IFileOpenDialog_Wrapper()
{
if (m_pInterface) {
m_pInterface->Release();
CoUninitialize();
}
}
示例8: fileOpenDialog
extern "C" LXCWIN_API HRESULT fileOpenDialog(HWND hWnd, DWORD *count, LPWSTR **result) {
*result = NULL;
HRESULT hr = S_OK;
CoInitialize(nullptr);
IFileOpenDialog *pfd = NULL;
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (SUCCEEDED(hr)) {
// set default folder to "My Documents"
IShellItem *psiDocuments = NULL;
hr = SHCreateItemInKnownFolder(FOLDERID_Documents, 0, NULL,
IID_PPV_ARGS(&psiDocuments));
if (SUCCEEDED(hr)) {
hr = pfd->SetDefaultFolder(psiDocuments);
psiDocuments->Release();
}
// dialog title
pfd->SetTitle(L"Select files to share");
// allow multiselect, restrict to real files
DWORD dwOptions;
hr = pfd->GetOptions(&dwOptions);
if (SUCCEEDED(hr)) {
// ideally, allow selecting folders as well as files, but IFileDialog does not support this :(
pfd->SetOptions(dwOptions | FOS_ALLOWMULTISELECT | FOS_FORCEFILESYSTEM); // | FOS_PICKFOLDERS
}
// do not limit to certain file types
// show the open file dialog
hr = pfd->Show(hWnd);
if (SUCCEEDED(hr)) {
IShellItemArray *psiaResults;
hr = pfd->GetResults(&psiaResults);
if (SUCCEEDED(hr)) {
hr = psiaResults->GetCount(count);
if (SUCCEEDED(hr)) {
*result = (LPWSTR*)calloc(*count, sizeof(LPWSTR));
if (*result != NULL) {
for (DWORD i = 0; i < *count; i++) {
IShellItem *resultItem = NULL;
hr = psiaResults->GetItemAt(i, &resultItem);
if (SUCCEEDED(hr)) {
resultItem->GetDisplayName(SIGDN_FILESYSPATH, &((*result)[i]));
resultItem->Release();
}
}
// paths now contains selected files
}
}
psiaResults->Release();
}
}
pfd->Release();
}
return hr;
}
示例9: getFilePathWithDialog
string getFilePathWithDialog()
{
string path = "";
HRESULT hr = CoInitializeEx(NULL, COINITBASE_MULTITHREADED |
COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
PWSTR pszFilePath;
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
//MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
char buffer[500];
wcstombs(buffer, pszFilePath, 500);
path = buffer;
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
return path;
}
示例10: openUserFileDiaglog
PWSTR openUserFileDiaglog()
{
PWSTR pszFilePath = NULL;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen = NULL;
// Create the FileOpenDialog object.
hr = CoCreateInstance(
CLSID_FileOpenDialog,
NULL,
CLSCTX_ALL,
IID_IFileOpenDialog,
(void**)&pFileOpen);
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem = NULL;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
return pszFilePath;
}
示例11: CoInitializeEx
const bool Core::select_file() {
//Open file dialog, straight from https://msdn.microsoft.com/en-us/library/windows/desktop/ff485843(v=vs.85).aspx
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
PWSTR pszFilePath = nullptr;
if (SUCCEEDED(hr)) {
IFileOpenDialog *pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr)) {
//Boilerplate for only showing *.nes files in the dialog. See the MSDN docs more info.
COMDLG_FILTERSPEC fileFilter;
fileFilter.pszName = L"iNES";
fileFilter.pszSpec = L"*.nes";
pFileOpen->SetFileTypes(1, &fileFilter);
pFileOpen->SetFileTypeIndex(1);
pFileOpen->SetDefaultExtension(L"nes");
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr)) {
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr)) {
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr)) {
logmsg("Opening file");
} else {
pszFilePath = nullptr;
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
if (pszFilePath == nullptr) {
alert_error("Unable to open file! File must have the extension \".nes\"");
return false;
}
//Convert wchar_t string to char string
std::size_t i;
wcstombs_s(&i, fileSelection, pszFilePath, MAX_PATH);
return true;
}
示例12: openFileGetName2
int openFileGetName2()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(hr))
{
IFileOpenDialog *pFileOpen;
// Create the FileOpenDialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL,
IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
if (SUCCEEDED(hr))
{
// Show the Open dialog box.
hr = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hr))
{
IShellItem *pItem;
hr = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hr))
{
hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &endnFile);
// Display the file name to the user.
if (SUCCEEDED(hr))
{
endnFILE = endnFile;
CoTaskMemFree(endnFile);
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
return 0;
}
示例13: ResStr
bool CPPageWebServer::PickDir(CString& dir)
{
CString strTitle = ResStr(IDS_PPAGEWEBSERVER_0);
bool success = false;
if (SysVersion::IsVistaOrLater()) {
CFileDialog dlg(TRUE);
IFileOpenDialog* openDlgPtr = dlg.GetIFileOpenDialog();
if (openDlgPtr != NULL) {
openDlgPtr->SetTitle(strTitle);
openDlgPtr->SetOptions(FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM | FOS_PATHMUSTEXIST);
// Typedef for function SHCreateItemFromParsingName
typedef HRESULT(STDAPICALLTYPE * PFN_TYPE_SHCreateItemFromParsingName)(PCWSTR /*pszPath*/, IBindCtx* /*pbc*/, REFIID /*riid*/, void** /*ppv*/);
// Load SHELL32.DLL to get pointer to aforementioned function
HINSTANCE hDllShell = ::LoadLibrary(_T("Shell32.dll"));
PFN_TYPE_SHCreateItemFromParsingName pfnSHCreateItemFromParsingName = NULL;
if (hDllShell != NULL) {
// Try to get the pointer to that function
pfnSHCreateItemFromParsingName = reinterpret_cast<PFN_TYPE_SHCreateItemFromParsingName>(::GetProcAddress(hDllShell, "SHCreateItemFromParsingName"));
}
if (pfnSHCreateItemFromParsingName != NULL) {
CComPtr<IShellItem> psiFolder;
if (SUCCEEDED(pfnSHCreateItemFromParsingName(dir, NULL, IID_PPV_ARGS(&psiFolder)))) {
openDlgPtr->SetFolder(psiFolder);
}
}
if (SUCCEEDED(openDlgPtr->Show(m_hWnd))) {
dir = dlg.GetFolderPath();
success = true;
}
openDlgPtr->Release();
}
} else {
TCHAR buff[_MAX_PATH];
BROWSEINFO bi;
bi.hwndOwner = m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = buff;
bi.lpszTitle = strTitle;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE | BIF_USENEWUI;
bi.lpfn = BrowseCtrlCallback;
bi.lParam = (LPARAM)(LPCTSTR)dir;
bi.iImage = 0;
LPITEMIDLIST iil = SHBrowseForFolder(&bi);
if (iil) {
SHGetPathFromIDList(iil, buff);
dir = buff;
success = true;
}
}
return success;
}
示例14: OpenFolder
/*
* OpenFileName
* Opens a folder dialog box, and returns the path
* Returns an empty string if dialog is canceled
*/
std::string OpenFolder(/*char *filter,*/ HWND owner) {
HRESULT hr;
IFileOpenDialog *pOpenFolderDialog;
std::string folderPath;
// CoCreate the dialog object.
hr = CoCreateInstance(CLSID_FileOpenDialog,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&pOpenFolderDialog));
if (SUCCEEDED(hr))
{
pOpenFolderDialog->SetOptions(FOS_PICKFOLDERS);
// Show the dialog
hr = pOpenFolderDialog->Show(owner);
if (SUCCEEDED(hr))
{
// Obtain the result of the user's interaction with the dialog.
IShellItem *psiResult;
hr = pOpenFolderDialog->GetResult(&psiResult);
LPWSTR folderW = NULL;
psiResult->GetDisplayName(SIGDN_FILESYSPATH, &folderW);
char* folderC;
folderC = new char[300];
folderPath = wcstombs(folderC,folderW, 300);
folderPath = folderC;
//free memory
if (folderC) delete[] folderC;
CoTaskMemFree ( folderW );
psiResult->Release();
}
}
pOpenFolderDialog->Release();
return folderPath;
}
示例15: MessageBox
std::string Dlg_MemBookmark::ImportDialog()
{
std::string str;
if ( g_pCurrentGameData->GetGameID() == 0 )
{
MessageBox( nullptr, _T("ROM not loaded: please load a ROM first!"), _T("Error!"), MB_OK );
return str;
}
IFileOpenDialog* pDlg = nullptr;
HRESULT hr = CoCreateInstance( CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>( &pDlg ) );
if ( hr == S_OK )
{
hr = pDlg->SetFileTypes( ARRAYSIZE( c_rgFileTypes ), c_rgFileTypes );
if ( hr == S_OK )
{
hr = pDlg->Show( nullptr );
if ( hr == S_OK )
{
IShellItem* pItem = nullptr;
hr = pDlg->GetResult( &pItem );
if ( hr == S_OK )
{
LPWSTR pStr = nullptr;
hr = pItem->GetDisplayName( SIGDN_FILESYSPATH, &pStr );
if ( hr == S_OK )
{
str = Narrow( pStr );
}
pItem->Release();
}
}
}
pDlg->Release();
}
return str;
}