fix file open dialog broken

pull/2/head
ink-soul 2023-06-01 09:32:07 +08:00
parent e5d0cb92cf
commit b748806ad8
5 changed files with 1758 additions and 1 deletions

View File

@ -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

View File

@ -18,6 +18,18 @@ bool GUIFunction::openFileFolderDialog()
hResult = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen)); 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)) if (SUCCEEDED(hResult))
{ {
// Show the Open dialog box. // Show the Open dialog box.

View File

@ -11,6 +11,7 @@ public:
PWSTR filePath; PWSTR filePath;
bool newModelFile;
bool openFileFolderDialog(); bool openFileFolderDialog();

View File

@ -1646,10 +1646,12 @@
{ {
} }
} }
if (overlay->header("Animation")) if (overlay->header("Animation"))
{ {
overlay->checkBox("Pause", &paused); overlay->checkBox("Pause", &paused);
} }
if (overlay->header("file")) if (overlay->header("file"))
{ {
if (overlay->button("select model")) if (overlay->button("select model"))
@ -1658,7 +1660,7 @@
if (guiFunc.openFileFolderDialog()) if (guiFunc.openFileFolderDialog())
{ {
std::cout << guiFunc.filePath << std::endl; MessageBoxW(NULL, guiFunc.filePath, L"File Path", MB_OK);
} }
else else
{ {