[win32] added basic mp_save_dialogue() implementation using COM IFileSaveDialog
This commit is contained in:
parent
e24500e18d
commit
49de9d0290
|
@ -406,8 +406,6 @@ int main()
|
|||
UI_STYLE_SIZE);
|
||||
widget_view("Buttons")
|
||||
{
|
||||
ui_button("Button 1");
|
||||
|
||||
if(ui_button("Test Dialog").clicked)
|
||||
{
|
||||
char* options[] = {"Accept", "Reject"};
|
||||
|
@ -427,6 +425,12 @@ int main()
|
|||
str8 file = mp_open_dialog(mem_scratch(), "Open File", 0, 0, 0, true);
|
||||
printf("selected file %.*s\n", (int)file.len, file.ptr);
|
||||
}
|
||||
|
||||
if(ui_button("Save").clicked)
|
||||
{
|
||||
str8 file = mp_save_dialog(mem_scratch(), "Save File", 0, 0, 0, true);
|
||||
printf("selected file %.*s\n", (int)file.len, file.ptr);
|
||||
}
|
||||
}
|
||||
|
||||
ui_style_next(&(ui_style){.size.width = {UI_SIZE_PARENT, 0.5},
|
||||
|
|
|
@ -1148,7 +1148,45 @@ MP_API str8 mp_save_dialog(mem_arena* arena,
|
|||
const char* title,
|
||||
const char* defaultPath,
|
||||
int filterCount,
|
||||
const char** filters);
|
||||
const char** filters)
|
||||
{
|
||||
str8 res = {0};
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
IFileOpenDialog* dialog = 0;
|
||||
hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_ALL, &IID_IFileSaveDialog, (void**)&dialog);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
hr = dialog->lpVtbl->Show(dialog, NULL);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
IShellItem* item;
|
||||
hr = dialog->lpVtbl->GetResult(dialog, &item);
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
PWSTR filePath;
|
||||
hr = item->lpVtbl->GetDisplayName(item, SIGDN_FILESYSPATH, &filePath);
|
||||
|
||||
if(SUCCEEDED(hr))
|
||||
{
|
||||
int utf8Size = WideCharToMultiByte(CP_UTF8, 0, filePath, -1, NULL, 0, NULL, NULL);
|
||||
if(utf8Size > 0)
|
||||
{
|
||||
res.ptr = mem_arena_alloc(arena, utf8Size);
|
||||
res.len = utf8Size-1;
|
||||
WideCharToMultiByte(CP_UTF8, 0, filePath, -1, res.ptr, utf8Size, NULL, NULL);
|
||||
}
|
||||
CoTaskMemFree(filePath);
|
||||
}
|
||||
item->lpVtbl->Release(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CoUninitialize();
|
||||
return(res);
|
||||
}
|
||||
|
||||
#include<commctrl.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue