plumageRender/enc_temp_folder/807fde3af9bee5f15fd89631b7f.../GUIFunction.cpp

68 lines
2.0 KiB
C++

#include "GUIFunction.h"
// win32 api IFileOpenDialog
// TO DO: rewrite this function to bool and get file path through public value
bool GUIFunction::openFileFolderDialog()
{
//initialize COM lib
HRESULT hResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hResult))
{
IFileOpenDialog* pFileOpen = nullptr;
hResult = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
DWORD fileFormatFlag;
hResult = pFileOpen->GetOptions(&fileFormatFlag);
hResult = pFileOpen->SetOptions(fileFormatFlag | FOS_FORCEFILESYSTEM);
COMDLG_FILTERSPEC fileType[] =
{
{L"gltf model files",L"*.gltf*"},
{L"gltf model files",L"*.GLTF*"},
};
hResult = pFileOpen->SetFileTypes(ARRAYSIZE(fileType), fileType);
hResult = pFileOpen->SetFileTypeIndex(0);
if (SUCCEEDED(hResult))
{
// Show the Open dialog box.
hResult = pFileOpen->Show(NULL);
// Get the file name from the dialog box.
if (SUCCEEDED(hResult))
{
IShellItem* pItem;
hResult = pFileOpen->GetResult(&pItem);
if (SUCCEEDED(hResult))
{
PWSTR pszFilePath;
hResult = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
filePath = pszFilePath;
// Display the file name to the user.
if (SUCCEEDED(hResult))
{
MessageBoxW(NULL, pszFilePath, L"File Path", MB_OK);
CoTaskMemFree(pszFilePath);
}
pItem->Release();
}
return true;
}
pFileOpen->Release();
return false;
}
CoUninitialize();
return false;
}
return false;
};