annotate src/gui.c @ 85:1acd477da42f

posix: improvements
author Paper <paper@paper.us.eu.org>
date Mon, 17 Jun 2024 21:18:37 -0400
parents c06dcab17923
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
1 /* mingw hack */
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
2 #ifdef UNICODE
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
3 #define NTDDI_VERSION 0x06000000
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
4 #define _WIN32_WINNT 0x0600
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
5 #else
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
6 #define _WIN32_WINNT 0x0400
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
7 #endif
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
8
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
9 #include <windef.h>
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
10 #include <winbase.h>
68
207684d44b54 gui.c: Add drag and drop support
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
11 #include <shlwapi.h>
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
12
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #include <stdint.h>
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
14 #include <stdio.h>
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
15
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
16 #include <tchar.h> /* tchar versions of string.h functions */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
17
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
18 #include "common.h"
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
19
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
20 /* make sure this is defined... */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
21 #ifndef _MAX_ULTOSTR_BASE10_COUNT
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
22 #define _MAX_ULTOSTR_BASE10_COUNT (10 + 1)
39
b32218b54640 Use ANSI instead of Unicode (Windows 95 support)
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
23 #endif
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
25 /* put all of our types in an array */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
26 static const enum types types[] = { TYPES_VF, TYPES_VEG };
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
27
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
28 /* HWND ids */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
29 enum {
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
30 OPEN_FILE_BUTTON = 0,
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
31 COMBOBOX,
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
32 LISTBOX,
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
33 SAVE_FILE_BUTTON,
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
34 VERSION
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
35 };
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
36
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
37 #if UNICODE
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
38 /* use COM when `UNICODE=1` to avoid file paths being cut off */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
39 #include <shobjidl.h>
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
40
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
41 static const DWORD COM_INITFLAGS = (COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
42 #endif
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
43
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
44 /* user-adjustable. set these values to whatever you want, the GUI will scale */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
45 #define WINDOW_WIDTH 225U
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
46 #define WINDOW_HEIGHT 200U
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
47
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
48 static LPTSTR file_path = NULL;
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
49
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
50 /* these values are loaded by AddControls() if they're valid */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
51 static uint8_t version = 11;
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
52 static enum types type = TYPES_VEG;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
53
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
54 /* we edit this from display_file() */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
55 static HWND hwnd_version = NULL;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
57 static inline LPCTSTR type_to_prefix(enum types type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
58 switch (type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
59 case TYPES_VF: return TEXT("MS");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
60 case TYPES_VEG: return TEXT("PRO");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
61 case TYPES_UNKNOWN:
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
62 default: return TEXT("UNK");
58
fcd4b9fe957b [gui.c]: show version and type in a box
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 56
diff changeset
63 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
64 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
65
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
66 static inline LPCTSTR type_to_string(enum types type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
67 switch (type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
68 case TYPES_VF: return TEXT("Movie Studio");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
69 case TYPES_VEG: return TEXT("Vegas Pro");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
70 case TYPES_UNKNOWN:
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
71 default: return TEXT("Unknown");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
72 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
73 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
74
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
75 static inline LPCTSTR type_to_extension(enum types type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
76 switch (type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
77 case TYPES_VF: return TEXT("vf");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
78 case TYPES_VEG:
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
79 case TYPES_UNKNOWN:
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
80 default: return TEXT("veg");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
81 }
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
84 /* these functions are designed to *not* use global variables,
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
85 * to make everything a bit more simple... */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
86 static int display_file(LPCTSTR path) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
87 /* Read the file to memory */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
88 FILE* file = _tfopen(path, TEXT("rb"));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
89
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
90 uint8_t file_version = 0;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
91 enum types file_type = TYPES_UNKNOWN;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
93 get_file_information(file, &file_version, &file_type);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
95 int needed = _sntprintf(NULL, 0, TEXT("File version: %s %u"), type_to_string(file_type), file_version);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
96 LPTSTR text = calloc(needed + 1, sizeof(TCHAR));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
97 if (!text) /* out of memory... lol */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
98 exit(1);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
99 _sntprintf(text, needed + 1, TEXT("File version: %s %u"), type_to_string(file_type), file_version);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
100
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
101 if (!SendMessage(hwnd_version, WM_SETTEXT, (WPARAM)0, (LPARAM)text)) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
102 free(text);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
103 return -1;
38
161ec4e87d0a Crash fix for Windows 2000 and XP
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 34
diff changeset
104 }
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
106 free(text);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
107 fclose(file);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
109 return 0;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
112 static int open_file(HWND hWnd, LPTSTR* filepath) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
113 #if UNICODE
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
114 if (CoInitializeEx(NULL, COM_INITFLAGS) != S_OK)
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
115 return -1; /* what */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
116
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
117 COMDLG_FILTERSPEC filters[] = {{L"Project files", L"*.veg;*.vf"}, {L"All files", L"*.*"}};
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
118
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
119 IFileDialog* pfd = NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
120 IShellItem* result = NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
121
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
122 if (SUCCEEDED(CoCreateInstance(&CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileOpenDialog, (LPVOID*)&pfd))) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
123 pfd->lpVtbl->SetFileTypes(pfd, ARRAYSIZE(filters), filters);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
124 pfd->lpVtbl->SetFileTypeIndex(pfd, 1);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
125 pfd->lpVtbl->Show(pfd, hWnd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
126
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
127 if (!SUCCEEDED(pfd->lpVtbl->GetResult(pfd, &result)) || !result) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
128 pfd->lpVtbl->Release(pfd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
129 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
130 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
131
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
132 if (!SUCCEEDED(result->lpVtbl->GetDisplayName(result, SIGDN_FILESYSPATH, filepath))) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
133 pfd->lpVtbl->Release(pfd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
134 result->lpVtbl->Release(result);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
135 *filepath = NULL; /* might memleak? */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
136 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
137 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
138
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
139 result->lpVtbl->Release(result);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
140 pfd->lpVtbl->Release(pfd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
141 } else {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
142 #endif
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
143 /* initialize our buffer */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
144 *filepath = calloc(MAX_PATH + 1, sizeof(TCHAR));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
145
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
146 OPENFILENAME ofn = {0};
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
147
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
148 /* NT 4.0 compat */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
149 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
150 ofn.hwndOwner = hWnd;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
151 ofn.lpstrFile = *filepath;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
152 ofn.nMaxFile = MAX_PATH;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
153 ofn.lpstrFilter = TEXT("Project files\0*.veg;*.vf\0All files\0*.*\0");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
154
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
155 if (!GetOpenFileName(&ofn))
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
156 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
157 #if UNICODE
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
158 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
159
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
160 CoUninitialize();
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
161 #endif
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
162
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
163 return display_file(*filepath);;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
164 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
165
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
166 static int save_file(HWND hWnd, LPCTSTR input, uint8_t version, enum types type) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
167 if (!input) {
52
cf9a14755472 Use Win32 libraries to copy files
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 51
diff changeset
168 MessageBox(hWnd,
cf9a14755472 Use Win32 libraries to copy files
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 51
diff changeset
169 TEXT("Please open a file first!"),
cf9a14755472 Use Win32 libraries to copy files
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 51
diff changeset
170 TEXT("Invalid input file!"),
cf9a14755472 Use Win32 libraries to copy files
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 51
diff changeset
171 MB_ICONEXCLAMATION);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
172 return -1;
38
161ec4e87d0a Crash fix for Windows 2000 and XP
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 34
diff changeset
173 }
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
174
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
175 LPTSTR output_template = NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
176 LPTSTR output = NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
177
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
178 {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
179 LPTSTR input_basename = PathFindFileName(input);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
180 int input_basename_len = PathFindExtension(input_basename) - input_basename;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
181
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
182 int needed = _sntprintf(NULL, 0, TEXT("%s_V%u_%.*s.%s"), type_to_prefix(type), version, input_basename_len, input_basename, type_to_extension(type));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
183 output_template = calloc(needed + 1, sizeof(TCHAR));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
184 _sntprintf(output_template, needed + 1, TEXT("%s_V%u_%.*s.%s"), type_to_prefix(type), version, input_basename_len, input_basename, type_to_extension(type));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
185
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
186 free(input_basename);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
187 }
68
207684d44b54 gui.c: Add drag and drop support
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
188
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
189 {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
190 /* File dialog */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
191 #if UNICODE
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
192 int com_initialized = SUCCEEDED(CoInitializeEx(NULL, COM_INITFLAGS));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
193
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
194 COMDLG_FILTERSPEC filters[] = {{L"Movie Studio project files", L"*.vf"}, {L"Vegas Pro project files", L"*.veg"}, {L"All files", L"*.*"}};
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
195
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
196 IFileDialog* pfd = NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
197 IShellItem* result = NULL;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
198 if (com_initialized && SUCCEEDED(CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSaveDialog, (LPVOID*)&pfd))) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
199 pfd->lpVtbl->SetFileTypes(pfd, ARRAYSIZE(filters), filters);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
200 pfd->lpVtbl->SetFileTypeIndex(pfd, (type == TYPES_UNKNOWN) ? ARRAYSIZE(filters) : type - TYPES_UNKNOWN);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
201 pfd->lpVtbl->SetFileName(pfd, output_template);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
202 pfd->lpVtbl->Show(pfd, hWnd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
203
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
204 if (!SUCCEEDED(pfd->lpVtbl->GetResult(pfd, &result))) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
205 pfd->lpVtbl->Release(pfd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
206 free(output_template);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
207 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
208 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
209
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
210 if (!SUCCEEDED(result->lpVtbl->GetDisplayName(result, SIGDN_FILESYSPATH, &output))) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
211 pfd->lpVtbl->Release(pfd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
212 result->lpVtbl->Release(result);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
213 free(output_template);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
214 output = NULL; /* might memleak ? */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
215 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
216 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
217
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
218 result->lpVtbl->Release(result);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
219 pfd->lpVtbl->Release(pfd);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
220 free(output_template);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
221 } else {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
222 #endif
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
223 /* fallback to OPENFILENAME if COM fucks up for whatever reason (or we're on ANSI)... */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
224 output = calloc(MAX_PATH + 1, sizeof(TCHAR));
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
225 _tcsncpy(output, output_template, MAX_PATH);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
226 free(output_template);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
227
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
228 OPENFILENAME ofn = {0};
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
229
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
230 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
231 ofn.hwndOwner = hWnd;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
232 ofn.lpstrFile = output;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
233 ofn.nMaxFile = MAX_PATH;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
234 ofn.lpstrFilter = TEXT("Movie Studio project files\0*.vf\0Vegas Pro project files\0*.veg\0All files\0*.*\0");
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
235 ofn.nFilterIndex = (type == TYPES_UNKNOWN) ? 3 : type - TYPES_UNKNOWN;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
236
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
237 if (!GetSaveFileName(&ofn))
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
238 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
239 #if UNICODE
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
240 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
241
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
242 if (com_initialized)
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
243 CoUninitialize();
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
244 #endif
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
245 }
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
246
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
247 if (!CopyFile(input, output, 0)) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
248 MessageBox(hWnd, TEXT("Failed to copy original project file! Does the destination file already exist?"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION | MB_OK);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
249 free(output);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
250 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
251 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
252
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
253 FILE* output_file = _tfopen(output, TEXT("ab"));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
254 if (!output_file) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
255 MessageBox(hWnd, TEXT("Failed to save project file!"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION | MB_OK);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
256 free(output);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
257 return -1;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
258 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
259
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
260 free(output);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
261
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
262 set_file_information(output_file, version, type);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
263
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
264 fclose(output_file);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
265
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
266 return 0;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
267 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
268
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
269 /* TODO: use a resource file instead... */
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
270 void AddControls(HWND hWnd) {
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
271 /* Open File */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
272 HWND open_button = CreateWindow(TEXT("Button"), TEXT("Open"), WS_VISIBLE | WS_CHILD, WINDOW_WIDTH * 7 / 18, WINDOW_HEIGHT / 40, WINDOW_WIDTH * 2 / 9, WINDOW_HEIGHT / 10, hWnd, (HMENU)OPEN_FILE_BUTTON, NULL, NULL);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
273
18
b5df3f47a30e Use enums for `type`
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 17
diff changeset
274 /* Versions */
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
275 HWND combobox = CreateWindow(TEXT("ComboBox"), NULL,
18
b5df3f47a30e Use enums for `type`
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 17
diff changeset
276 CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_VSCROLL,
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
277 WINDOW_WIDTH * 7 / 18, WINDOW_HEIGHT * 3 / 20, WINDOW_WIDTH * 2 / 9, WINDOW_HEIGHT,
68
207684d44b54 gui.c: Add drag and drop support
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
278 hWnd, (HMENU)COMBOBOX, NULL, NULL);
207684d44b54 gui.c: Add drag and drop support
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
279
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
280 for (size_t v = 8; v <= 21; v++) {
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
281 TCHAR v_str[_MAX_ULTOSTR_BASE10_COUNT] = {'\0'};
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
282
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
283 _ultot(v, v_str, 10);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
284
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
285 LRESULT pos = SendMessage(combobox, CB_ADDSTRING, 0, (LPARAM)v_str);
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
286 SendMessage(combobox, CB_SETITEMDATA, pos, v);
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
287 if (v == version)
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
288 SendMessage(combobox, CB_SETCURSEL, pos, 0);
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
289 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
290
18
b5df3f47a30e Use enums for `type`
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 17
diff changeset
291 /* Type */
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
292 HWND listbox = CreateWindow(TEXT("Listbox"), NULL, WS_VISIBLE | WS_CHILD | LBS_STANDARD | LBS_NOTIFY, WINDOW_WIDTH * 5 / 18, WINDOW_HEIGHT * 11 / 40, WINDOW_WIDTH * 4 / 9, WINDOW_HEIGHT / 5, hWnd, (HMENU)LISTBOX, NULL, NULL);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
293
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
294 for (size_t i = 0; i < ARRAYSIZE(types); i++) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
295 LRESULT pos = SendMessage(listbox, LB_ADDSTRING, i, (LPARAM)type_to_string(types[i]));
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
296 SendMessage(listbox, LB_SETITEMDATA, pos, types[i]);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
297 if (types[i] == type)
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
298 SendMessage(listbox, LB_SETCURSEL, pos, 0);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
299 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
300
18
b5df3f47a30e Use enums for `type`
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 17
diff changeset
301 /* Save File */
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
302 HWND save_button = CreateWindow(TEXT("Button"), TEXT("Save"), WS_VISIBLE | WS_CHILD, WINDOW_WIDTH * 7 / 18, WINDOW_HEIGHT * 9 / 20, WINDOW_WIDTH * 2 / 9, WINDOW_HEIGHT / 10, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
303
58
fcd4b9fe957b [gui.c]: show version and type in a box
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 56
diff changeset
304 /* Version and Type display */
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
305 hwnd_version = CreateWindow(TEXT("Edit"), TEXT("No file opened!"), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_READONLY | ES_CENTER | ES_MULTILINE | SS_CENTER, WINDOW_WIDTH / 6, WINDOW_HEIGHT * 3 / 5, WINDOW_WIDTH * 2 / 3, WINDOW_HEIGHT / 5, hWnd, (HMENU)VERSION, NULL, NULL);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
306 if (!open_button || !save_button || !listbox || !combobox || !hwnd_version)
52
cf9a14755472 Use Win32 libraries to copy files
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 51
diff changeset
307 MessageBox(hWnd, TEXT("how did you even trigger this"), TEXT("GUI could not be initialized!"), MB_ICONEXCLAMATION);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
308 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
309
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
310 /* Make the fonts not as ugly */
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
311 BOOL CALLBACK SetFont(HWND child, LPARAM font) {
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
312 SendMessage(child, WM_SETFONT, font, 1);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
313 return 1;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
314 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
315
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
316 LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
317 switch(msg) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
318 case WM_COMMAND:
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
319 if (HIWORD(wParam) == CBN_SELCHANGE) {
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
320 switch (LOWORD(wParam)) {
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
321 case COMBOBOX: {
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
322 LRESULT i = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
323 version = (uint8_t)SendMessage((HWND)lParam, CB_GETITEMDATA, i, 0);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
324 break;
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
325 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
326 case LISTBOX: {
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
327 LRESULT i = SendMessage((HWND)lParam, LB_GETCURSEL, 0, 0);
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
328 type = (enum types)SendMessage((HWND)lParam, LB_GETITEMDATA, i, 0);
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
329 break;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
330 }
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
331 default:
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
332 break;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
333 }
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
334 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
335
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
336 switch (wParam) {
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
337 case OPEN_FILE_BUTTON:
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
338 /* free(NULL) == no-op */
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
339 free(file_path);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
340 open_file(hWnd, &file_path);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
341 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
342 case SAVE_FILE_BUTTON:
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
343 save_file(hWnd, file_path, version, type);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
344 break;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
345 default:
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
346 break;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
347 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
348 break;
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
349 case WM_CREATE:
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
350 AddControls(hWnd);
81
c06dcab17923 *: change license to BSD, update README for Unicode
Paper <paper@paper.us.eu.org>
parents: 79
diff changeset
351 EnumChildWindows(hWnd, SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT));
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
352 break;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
353 case WM_DESTROY:
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
354 PostQuitMessage(0);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
355 break;
69
79a35af2cb56 gui.c: Add angled brackets around case
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 68
diff changeset
356 case WM_DROPFILES: {
68
207684d44b54 gui.c: Add drag and drop support
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
357 /* Drag and drop support */
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
358 free(file_path);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
359
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
360 HDROP drop = (HDROP)wParam;
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
361
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
362 int needed = DragQueryFile(drop, 0, NULL, 0);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
363 file_path = malloc((needed + 1) * sizeof(TCHAR));
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
364 DragQueryFile(drop, 0, file_path, needed + 1);
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
365 file_path[needed] = L'\0';
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
366
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
367 display_file(file_path);
68
207684d44b54 gui.c: Add drag and drop support
Paper <mrpapersonic@gmail.com>
parents: 63
diff changeset
368 break;
69
79a35af2cb56 gui.c: Add angled brackets around case
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 68
diff changeset
369 }
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
370 default:
51
0f6c604b6863 We don't need to specify that it's ANSI
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 47
diff changeset
371 return DefWindowProc(hWnd, msg, wParam, lParam);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
372 }
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
373 return 0;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
374 }
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
375
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
376 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR args, int ncmdshow) {
51
0f6c604b6863 We don't need to specify that it's ANSI
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 47
diff changeset
377 WNDCLASS wc = {0};
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
378
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
379 wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
380 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
381 wc.hInstance = hInstance;
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
382 wc.lpszClassName = TEXT("msvpvf");
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
383 wc.lpfnWndProc = WindowProcedure;
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
384
51
0f6c604b6863 We don't need to specify that it's ANSI
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 47
diff changeset
385 if (!RegisterClass(&wc)) return -1;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
386
79
8f90d5addda9 *: refactor... basically everything!
Paper <paper@paper.us.eu.org>
parents: 69
diff changeset
387 CreateWindowEx(WS_EX_ACCEPTFILES, TEXT("msvpvf"), TEXT("Movie Studio / Vegas Pro version spoofer"), WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, CW_USEDEFAULT, CW_USEDEFAULT, WINDOW_WIDTH, WINDOW_HEIGHT, NULL, NULL, hInstance, NULL);
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
388
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
389 MSG msg = {0};
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
390
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
391 while (GetMessage(&msg, NULL, 0, 0)) {
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
392 TranslateMessage(&msg);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
393 DispatchMessage(&msg);
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
394 }
39
b32218b54640 Use ANSI instead of Unicode (Windows 95 support)
Paper <37962225+mrpapersonic@users.noreply.github.com>
parents: 38
diff changeset
395 return 0;
6
d1e5b8390cd3 Add Windows GUI version and a multitude of other changes
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
396 }