当前位置: 首页>>代码示例>>C++>>正文


C++ IFileOpenDialog::GetResult方法代码示例

本文整理汇总了C++中IFileOpenDialog::GetResult方法的典型用法代码示例。如果您正苦于以下问题:C++ IFileOpenDialog::GetResult方法的具体用法?C++ IFileOpenDialog::GetResult怎么用?C++ IFileOpenDialog::GetResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFileOpenDialog的用法示例。


在下文中一共展示了IFileOpenDialog::GetResult方法的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;
}
开发者ID:arbiter34,项目名称:Win32NES,代码行数:35,代码来源:Win32NES.cpp

示例2: select_file

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;
}
开发者ID:mgukowsky,项目名称:MAGSNES,代码行数:57,代码来源:Core.cpp

示例3: 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);
}
开发者ID:TimSC,项目名称:wmf-video-player-example,代码行数:58,代码来源:winmain.cpp

示例4: qt_win_CID_get_existing_directory

QString qt_win_CID_get_existing_directory(const QFileDialogArgs &args)
{
    QString result;
    QDialog modal_widget;
    modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
    modal_widget.setParent(args.parent, Qt::Window);
    QApplicationPrivate::enterModal(&modal_widget);

    IFileOpenDialog *pfd = 0;
    HRESULT hr = CoCreateInstance(QT_CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER,
                                  QT_IID_IFileOpenDialog, reinterpret_cast<void**>(&pfd));

    if (SUCCEEDED(hr)) {
        qt_win_set_IFileDialogOptions(pfd, args.selection,
                                      args.directory, args.caption,
                                      QStringList(), QFileDialog::ExistingFile,
                                      args.options);

        // Set the FOS_PICKFOLDERS flag
        DWORD newOptions;
        hr = pfd->GetOptions(&newOptions);
        newOptions |= (FOS_PICKFOLDERS | FOS_FORCEFILESYSTEM);
        if (SUCCEEDED(hr) && SUCCEEDED((hr = pfd->SetOptions(newOptions)))) {
            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 result
                IShellItem *psi = 0;
                hr = pfd->GetResult(&psi);
                if (SUCCEEDED(hr)) {
                    // Retrieve the file name from shell item.
                    wchar_t *pszPath;
                    hr = psi->GetDisplayName(SIGDN_FILESYSPATH, &pszPath);
                    if (SUCCEEDED(hr)) {
                        result = QString::fromWCharArray(pszPath);
                        CoTaskMemFree(pszPath);
                    }
                    psi->Release(); // Free the current item.
                }
            }
        }
    }
    QApplicationPrivate::leaveModal(&modal_widget);

    qt_win_eatMouseMove();

    if (pfd)
        pfd->Release();
    return result;
}
开发者ID:AtlantisCD9,项目名称:Qt,代码行数:56,代码来源:qfiledialog_win.cpp

示例5: showDialog

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
}
开发者ID:lucaszardo,项目名称:SCV,代码行数:54,代码来源:FileOpen.cpp

示例6: 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;
}
开发者ID:elepro,项目名称:Anthony,代码行数:51,代码来源:Anthony.cpp

示例7: LoadMap

void EditorScreen::LoadMap()
{
	HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
        COINIT_DISABLE_OLE1DDE);
	
    if (SUCCEEDED(hr))
    {
		IFileOpenDialog *pFileOpen = NULL;

		HRESULT hr = CoCreateInstance(__uuidof(FileOpenDialog), NULL, 
        CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileOpen));

		if (SUCCEEDED(hr))
		{
			hr = pFileOpen->SetDefaultExtension(L"xml");
			hr = pFileOpen->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
			hr = pFileOpen->Show(NULL);

			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))
					{
						// Reset current Map information
						ResetMap();

						std::string filePath = utf8_encode(pszFilePath);
						map->LoadMap(filePath);

						CoTaskMemFree(pszFilePath);
					}
					pItem->Release();
				}
			}
			pFileOpen->Release();
		}
		CoUninitialize();
	}
}
开发者ID:shane1090,项目名称:Frostbite-Sienna,代码行数:47,代码来源:EditorScreen.cpp

示例8: 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;
}
开发者ID:and0p,项目名称:NesVoxel,代码行数:45,代码来源:Game.cpp

示例9: 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;
}
开发者ID:yorickdewid,项目名称:yCrypt,代码行数:43,代码来源:yCrypt.cpp

示例10: fileSaveDialog

extern "C" LXCWIN_API HRESULT fileSaveDialog(HWND hWnd, LPWSTR dialogTitle, LPWSTR *result) {
    *result = NULL;
    HRESULT hr = S_OK;
    CoInitialize(nullptr);
    IFileOpenDialog *pfd = NULL;// yes, *open*, since this dialog selects an existing parent dir, not a new file
    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(dialogTitle);

        // ok button text
        pfd->SetOkButtonLabel(L"Choose target");

        // only choose directories
        DWORD dwOptions;
        hr = pfd->GetOptions(&dwOptions);
        if (SUCCEEDED(hr)) {
            pfd->SetOptions(dwOptions | FOS_PICKFOLDERS);
        }

        // show the save dialog
        hr = pfd->Show(hWnd);
        if (SUCCEEDED(hr)) {
            IShellItem *psiaResult;
            hr = pfd->GetResult(&psiaResult);
            if (SUCCEEDED(hr)) {
                psiaResult->GetDisplayName(SIGDN_FILESYSPATH, &(*result));
                psiaResult->Release();
            }
        }
        pfd->Release();
    }
    return hr;
}
开发者ID:tfg13,项目名称:LanXchange,代码行数:43,代码来源:lxcwin.cpp

示例11: 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;
}
开发者ID:nairdan2,项目名称:project_hoshou,代码行数:41,代码来源:project_hoshou.cpp

示例12: fileName

void gameOfLife3D::MainWnd::OnOpenFile()
{
    static COMDLG_FILTERSPEC dialogFiltersMM[] = {
        { L"Life File(*.lif;*.life)", L"*.lif;*.life" },
        { L"All types(*.*)", L"*.*" },
    };

    IFileOpenDialog *pFileOpenDialog = nullptr;

    HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog,
                                  nullptr,
                                  CLSCTX_INPROC_SERVER,
                                  IID_PPV_ARGS(&pFileOpenDialog));

    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->SetFileTypes(2, dialogFiltersMM);
    }
    IShellItem *pResult = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->Show(m_hwnd);
    }
    if (SUCCEEDED(hr)) {
        hr = pFileOpenDialog->GetResult(&pResult);
    }
    WCHAR *pPath = nullptr;
    if (SUCCEEDED(hr)) {
        hr = pResult->GetDisplayName(SIGDN_FILESYSPATH, &pPath);
    }
    if (SUCCEEDED(hr)) {
        std::wstring fileName(pPath);
        auto lifeFile = std::make_shared<gameOfLife3D::io::LifeFile>();
        lifeFile->Load(fileName);
        m_canvasPanel->SetLifeFile(lifeFile);
    }
    if (pPath != nullptr) {
        CoTaskMemFree(pPath);
    }
    SafeRelease(&pResult);
    SafeRelease(&pFileOpenDialog);
}
开发者ID:dreamsxin,项目名称:GameOfLife3D,代码行数:40,代码来源:MainWnd.cpp

示例13: 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;
}
开发者ID:Tetriste,项目名称:LudumDare29,代码行数:45,代码来源:FileSyst.cpp

示例14: ImportDialog

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;
}
开发者ID:SyrianBallaS,项目名称:RASuite,代码行数:40,代码来源:RA_Dlg_MemBookmark.cpp

示例15: PromptFileLocation

bool PromptFileLocation(std::wstring& resultPath, std::wstring title=L"Open", fileType filterType=ft_exe)
{
    HRESULT hr;
    
    hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
    if (!SUCCEEDED(hr))
    {
        CoUninitialize();
        return false;
    }

    IFileOpenDialog *pFileOpen;
    // Create the FileOpenDialog object.
    hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Set the filter type
    switch (filterType)
    {
    case ft_exe:
            {
                COMDLG_FILTERSPEC filter;
                filter.pszName = L"Windows Executable";
                filter.pszSpec = L"*.exe";
                hr = pFileOpen->SetFileTypes(1, &filter);
                break;
            }
    default:
        {
            break;
        }
    }
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Set the title
    hr = pFileOpen->SetTitle(L"Please locate your Blender executable.");
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Show the Open dialog box.
    hr = pFileOpen->Show(NULL);
    if (!SUCCEEDED(hr))
    {
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    // Get the file name from the open dialog box.
    IShellItem *pItem;
    hr = pFileOpen->GetResult(&pItem);
    if (!SUCCEEDED(hr))
    {
        pItem->Release();
        pFileOpen->Release();
        CoUninitialize();
        return false;
    }

    PWSTR pszFilePath;
    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);

    if (!SUCCEEDED(hr))
    {
        pItem->Release();
        pFileOpen->Release();
        CoUninitialize();
        CoTaskMemFree(pszFilePath);
        return false;
    }

    resultPath = pszFilePath;
    CoTaskMemFree(pszFilePath);
    pItem->Release();
    pFileOpen->Release();
    CoUninitialize();
    return true;
}
开发者ID:BeigeAlert,项目名称:Blender_Compile_Utility,代码行数:92,代码来源:BlenderCompiler.cpp


注:本文中的IFileOpenDialog::GetResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。