fix file open dialog broken
parent
e5d0cb92cf
commit
b748806ad8
|
@ -0,0 +1,68 @@
|
|||
|
||||
#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;
|
||||
|
||||
};
|
File diff suppressed because it is too large
Load Diff
|
@ -18,6 +18,18 @@ bool GUIFunction::openFileFolderDialog()
|
|||
|
||||
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.
|
||||
|
|
|
@ -11,6 +11,7 @@ public:
|
|||
|
||||
PWSTR filePath;
|
||||
|
||||
bool newModelFile;
|
||||
|
||||
|
||||
bool openFileFolderDialog();
|
||||
|
|
|
@ -1646,10 +1646,12 @@
|
|||
{
|
||||
}
|
||||
}
|
||||
|
||||
if (overlay->header("Animation"))
|
||||
{
|
||||
overlay->checkBox("Pause", &paused);
|
||||
}
|
||||
|
||||
if (overlay->header("file"))
|
||||
{
|
||||
if (overlay->button("select model"))
|
||||
|
@ -1658,7 +1660,7 @@
|
|||
|
||||
if (guiFunc.openFileFolderDialog())
|
||||
{
|
||||
std::cout << guiFunc.filePath << std::endl;
|
||||
MessageBoxW(NULL, guiFunc.filePath, L"File Path", MB_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue