feat: 初步完成GUI界面添加
Some checks failed
构建上传工具 / build-tool (push) Failing after 2m9s

This commit is contained in:
2025-10-13 21:32:02 +08:00
parent 3b6705d6ef
commit cccb31cbc5
10 changed files with 607 additions and 74 deletions

View File

@@ -0,0 +1,56 @@
#include "windows_dialog.h"
#include <stdio.h>
#include <stdlib.h>
char* OpenFolderDialog(void) {
IFileOpenDialog *pFileOpen = NULL;
IShellItem *pItem = NULL;
PWSTR pszFilePath = NULL;
char* result = NULL;
// 初始化COM库
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
if (FAILED(hr)) {
return NULL;
}
// 创建FileOpenDialog对象
hr = CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_ALL, &IID_IFileOpenDialog, (void**)&pFileOpen);
if (SUCCEEDED(hr)) {
// 设置为选择文件夹模式
DWORD options;
pFileOpen->lpVtbl->GetOptions(pFileOpen, &options);
pFileOpen->lpVtbl->SetOptions(pFileOpen, options | FOS_PICKFOLDERS);
// 显示对话框
hr = pFileOpen->lpVtbl->Show(pFileOpen, NULL);
if (SUCCEEDED(hr)) {
// 获取结果
hr = pFileOpen->lpVtbl->GetResult(pFileOpen, &pItem);
if (SUCCEEDED(hr)) {
// 获取文件夹路径
hr = pItem->lpVtbl->GetDisplayName(pItem, SIGDN_FILESYSPATH, &pszFilePath);
if (SUCCEEDED(hr)) {
// 计算所需缓冲区大小并转换宽字符串到多字节字符串
int size_needed = WideCharToMultiByte(CP_UTF8, 0, pszFilePath, -1, NULL, 0, NULL, NULL);
result = (char*)malloc(size_needed);
if (result) {
WideCharToMultiByte(CP_UTF8, 0, pszFilePath, -1, result, size_needed, NULL, NULL);
}
CoTaskMemFree(pszFilePath);
}
pItem->lpVtbl->Release(pItem);
}
}
pFileOpen->lpVtbl->Release(pFileOpen);
}
CoUninitialize();
return result;
}
void FreeMemory(char* ptr) {
if (ptr) {
free(ptr);
}
}