update for file open dialog

pull/2/head
InkSoul 2023-05-31 15:30:58 +08:00
parent 46b3d24dd7
commit 88660a8f35
3 changed files with 75 additions and 1 deletions

View File

@ -30,7 +30,7 @@ function(buildHomework HOMEWORK_NAME)
# Add optional readme / tutorial # Add optional readme / tutorial
file(GLOB README_FILES "${HOMEWORK_FOLDER}/*.md") file(GLOB README_FILES "${HOMEWORK_FOLDER}/*.md")
if(WIN32) if(WIN32)
add_executable(${HOMEWORK_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES} "render/glTFModel.h" "render/glTFModel.cpp") add_executable(${HOMEWORK_NAME} WIN32 ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES} "render/glTFModel.h" "render/glTFModel.cpp" "render/GUIFunction.h" "render/GUIFunction.cpp")
target_link_libraries(${HOMEWORK_NAME} base ${Vulkan_LIBRARY} ${WINLIBS}) target_link_libraries(${HOMEWORK_NAME} base ${Vulkan_LIBRARY} ${WINLIBS})
else(WIN32) else(WIN32)
add_executable(${HOMEWORK_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES}) add_executable(${HOMEWORK_NAME} ${MAIN_CPP} ${SOURCE} ${MAIN_HEADER} ${SHADERS_GLSL} ${SHADERS_HLSL} ${README_FILES})

View File

@ -0,0 +1,47 @@
#include "GUIFunction.h"
// win32 api IFileOpenDialog
PWSTR GUIFunction::openFileFolderDialog(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
//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));
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);
// Display the file name to the user.
if (SUCCEEDED(hResult))
{
MessageBoxW(NULL, pszFilePath, L"File Path", MB_OK);
CoTaskMemFree(pszFilePath);
stringFilePath == pszFilePath;
}
pItem->Release();
}
}
pFileOpen->Release();
}
CoUninitialize();
}
return stringFilePath;
};

View File

@ -0,0 +1,27 @@
#pragma once
#include <cstdio>
#include <string>
#include <shobjidl.h>
#include <windows.h>
class GUIFunction
{
public:
GUIFunction();
~GUIFunction();
PWSTR openFileFolderDialog(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow);
private:
PWSTR stringFilePath;
};
GUIFunction::GUIFunction()
{
}
GUIFunction::~GUIFunction()
{
}