finish file open dialog

pull/2/head
ink-soul 2023-06-01 10:48:46 +08:00
parent b748806ad8
commit e308f2ac18
5 changed files with 27 additions and 1763 deletions

View File

@ -1,68 +0,0 @@
#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

@ -5,11 +5,11 @@
// win32 api IFileOpenDialog
// TO DO: rewrite this function to bool and get file path through public value
bool GUIFunction::openFileFolderDialog()
std::string GUIFunction::openFileFolderDialog()
{
//initialize COM lib
std::string strFilePath = GUIFunction::strFilePath;
HRESULT hResult = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (SUCCEEDED(hResult))
@ -43,26 +43,34 @@ bool GUIFunction::openFileFolderDialog()
if (SUCCEEDED(hResult))
{
PWSTR pszFilePath;
std::wstring wstrFilePath;
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);
wstrFilePath = pszFilePath;
CoTaskMemFree(pszFilePath);
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
strFilePath = converter.to_bytes(wstrFilePath);
}
pItem->Release();
}
return true;
}
pFileOpen->Release();
return false;
}
CoUninitialize();
return false;
}
return false;
return strFilePath;
};

View File

@ -2,19 +2,23 @@
#include <cstdio>
#include <string>
#include <locale>
#include <codecvt>
#include <shobjidl.h>
#include <windows.h>
#include <vulkanexamplebase.h>
class GUIFunction
{
public:
PWSTR filePath;
PWSTR glTFFilePath ;
std::string strFilePath = getAssetPath() + "buster_drone/busterDrone.gltf";
bool newModelFile;
bool openFileFolderDialog();
std::string openFileFolderDialog();
private:
};

View File

@ -1657,15 +1657,9 @@
if (overlay->button("select model"))
{
GUIFunction guiFunc{};
if (guiFunc.openFileFolderDialog())
{
MessageBoxW(NULL, guiFunc.filePath, L"File Path", MB_OK);
}
else
{
std::cerr << "file select error" << std::endl;
}
std::string strModelFilePath;
strModelFilePath = guiFunc.openFileFolderDialog();
std::cout << strModelFilePath << std::endl;
}
}
}