-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileDialog.c
45 lines (38 loc) · 1.08 KB
/
FileDialog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "FileDialog.h"
#include "debugmalloc.h"
#ifdef __WINDOWS__
char *open_file_dialog(SDL_Window *owner, const char *filter, const char *title, DialogType type) {
char file[MAX_PATH];
SDL_SysWMinfo wMinfo;
SDL_VERSION(&wMinfo.version);
if (!SDL_GetWindowWMInfo(owner, &wMinfo)) {
const char *error = SDL_GetError();
error = SDL_GetError();
}
OPENFILENAMEA ofn;
ZeroMemory(&file, sizeof(file));
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = wMinfo.info.win.window;
ofn.lpstrFilter = filter;
ofn.lpstrFile = file;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = title;
ofn.Flags = OFN_DONTADDTORECENT;
ofn.lpstrDefExt = ".sch";
if (type == DT_OPEN)
ofn.Flags |= OFN_PATHMUSTEXIST;
else if (type == DT_SAVE)
ofn.Flags |= OFN_OVERWRITEPROMPT;
bool successful;
if (type == DT_OPEN)
successful = GetOpenFileNameA(&ofn);
else if (type == DT_SAVE)
successful = GetSaveFileNameA(&ofn);
if (successful == false)
return NULL;
char *result = (char *) malloc(sizeof(char) * (strlen(file) + 1));
strcpy(result, file);
return result;
}
#endif