Mercurial > msvpvf
comparison src/gui.c @ 58:fcd4b9fe957b
[gui.c]: show version and type in a box
author | Paper <37962225+mrpapersonic@users.noreply.github.com> |
---|---|
date | Thu, 21 Jul 2022 00:46:18 -0400 |
parents | 0d62f49c1948 |
children | a2e979245441 |
comparison
equal
deleted
inserted
replaced
57:01c605e78f48 | 58:fcd4b9fe957b |
---|---|
29 #include <commdlg.h> | 29 #include <commdlg.h> |
30 #include "../include/common.h" | 30 #include "../include/common.h" |
31 #define _WIN32_WINNT 0x0400 | 31 #define _WIN32_WINNT 0x0400 |
32 #define ARRAYSIZE(a) \ | 32 #define ARRAYSIZE(a) \ |
33 sizeof(a)/sizeof(a[0]) | 33 sizeof(a)/sizeof(a[0]) |
34 #define OPEN_FILE_BUTTON 0 | 34 #define OPEN_FILE_BUTTON 0 |
35 #define COMBOBOX 1 | 35 #define COMBOBOX 1 |
36 #define LISTBOX 2 | 36 #define LISTBOX 2 |
37 #define SAVE_FILE_BUTTON 3 | 37 #define SAVE_FILE_BUTTON 3 |
38 #define VERSION 4 | |
38 #ifdef _MSC_VER | 39 #ifdef _MSC_VER |
39 #define strdup(p) _strdup(p) | 40 #define strdup(p) _strdup(p) |
40 #endif | 41 #endif |
41 | 42 |
42 HWND hWndListBox, hWndComboBox; | 43 HWND hWndListBox, hWndComboBox, hWndVersion; |
43 int16_t version = 13; | 44 int16_t version = 13; |
44 enum types { | 45 enum types { |
45 vf, | 46 vf, |
46 veg | 47 veg |
47 } type; | 48 } type; |
48 char* file_name = " "; | 49 char* file_name = " "; |
49 | 50 |
50 void display_file(char* path) { | 51 void display_file(char* path) { |
51 /* Read the file to memory */ | 52 /* Read the file to memory */ |
52 /* eventually this will contain code to show the version and type */ | |
53 FILE* file; | 53 FILE* file; |
54 file = fopen(path, "rb"); | 54 file = fopen(path, "rb"); |
55 fseek(file, 0, SEEK_END); | 55 fseek(file, 0x46, SEEK_SET); |
56 int _size = ftell(file); | 56 int f_version = fgetc(file); |
57 rewind(file); | 57 fseek(file, 0x18, SEEK_SET); |
58 char* data = calloc(_size+1, sizeof(char*)); | 58 TCHAR p[32]; |
59 fread(data, _size, 1, file); | 59 switch (fgetc(file)) { |
60 data[_size] = '\0'; | 60 case 0xEF: |
61 | 61 snprintf(p, 32, "File version: %s %d", "VEGAS Pro", f_version); |
62 free(data); | 62 break; |
63 case 0xF6: | |
64 snprintf(p, 32, "File version: %s %d", "Movie Studio", f_version); | |
65 break; | |
66 default: | |
67 snprintf(p, 32, "File version: %s %d", "Unknown", f_version); | |
68 break; | |
69 } | |
70 printf("%s", p); | |
71 SendMessage(hWndVersion, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | |
63 fclose(file); | 72 fclose(file); |
64 } | 73 } |
65 | 74 |
66 char* open_file(HWND hWnd) { | 75 char* open_file(HWND hWnd) { |
67 OPENFILENAME ofn; | 76 OPENFILENAME ofn; |
116 FILE* output = fopen(output_file, "r+b"); | 125 FILE* output = fopen(output_file, "r+b"); |
117 if (output == NULL) { | 126 if (output == NULL) { |
118 MessageBox(hWnd, TEXT("Failed to save project file!"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION); | 127 MessageBox(hWnd, TEXT("Failed to save project file!"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION); |
119 return; | 128 return; |
120 } | 129 } |
121 | 130 unsigned char* magic; |
122 switch ((int)type) { | 131 static const unsigned char magic_veg[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; |
123 case vf: { | 132 static const unsigned char magic_vf[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; |
124 unsigned char magic[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, | 133 if (type == veg) |
125 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; | 134 memcpy(magic, magic_veg, sizeof(magic_veg)); |
126 set_data(magic, version, output); | 135 else |
127 break; | 136 memcpy(magic, magic_vf, sizeof(magic_vf) ); |
128 } | 137 |
129 default: { | 138 set_data(magic, version, output); |
130 unsigned char magic[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, | |
131 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; | |
132 set_data(magic, version, output); | |
133 break; | |
134 } | |
135 } | |
136 | 139 |
137 fclose(output); | 140 fclose(output); |
138 } | 141 } |
139 | 142 |
140 void AddControls(HWND hWnd) { | 143 void AddControls(HWND hWnd) { |
166 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]); | 169 int pos = (int)SendMessage(hWndListBox, LB_ADDSTRING, i, (LPARAM) listbox_items[i]); |
167 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i); | 170 SendMessage(hWndListBox, LB_SETITEMDATA, pos, (LPARAM) i); |
168 } | 171 } |
169 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); | 172 SendMessage(hWndListBox, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); |
170 /* Save File */ | 173 /* Save File */ |
171 HWND save_button = CreateWindowA("Button", "Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL); | 174 HWND save_button = CreateWindow("Button", "Save", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 90, 50, 20, hWnd, (HMENU)SAVE_FILE_BUTTON, NULL, NULL); |
175 /* Version and Type display */ | |
176 hWndVersion = CreateWindow("Edit", "", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_READONLY | ES_CENTER | ES_MULTILINE | SS_CENTER, (int)((225 - 150)/2), 120, 150, 40, hWnd, (HMENU)VERSION, NULL, NULL); | |
172 if (open_button == NULL || save_button == NULL || hWndListBox == NULL || hWndComboBox == NULL) | 177 if (open_button == NULL || save_button == NULL || hWndListBox == NULL || hWndComboBox == NULL) |
173 MessageBox(hWnd, TEXT("how did you even trigger this"), TEXT("GUI could not be initialized!"), MB_ICONEXCLAMATION); | 178 MessageBox(hWnd, TEXT("how did you even trigger this"), TEXT("GUI could not be initialized!"), MB_ICONEXCLAMATION); |
174 } | 179 } |
175 | 180 |
176 bool CALLBACK SetFont(HWND child, LPARAM font) { | 181 bool CALLBACK SetFont(HWND child, LPARAM font) { |
190 switch(wParam) { | 195 switch(wParam) { |
191 case OPEN_FILE_BUTTON: | 196 case OPEN_FILE_BUTTON: |
192 file_name = open_file(hWnd); | 197 file_name = open_file(hWnd); |
193 case COMBOBOX: | 198 case COMBOBOX: |
194 case LISTBOX: | 199 case LISTBOX: |
200 case VERSION: | |
195 break; | 201 break; |
196 case SAVE_FILE_BUTTON: | 202 case SAVE_FILE_BUTTON: |
197 save_file(hWnd, file_name); | 203 save_file(hWnd, file_name); |
198 break; | |
199 } | 204 } |
200 break; | 205 break; |
201 case WM_CREATE: { | 206 case WM_CREATE: { |
202 AddControls(hWnd); | 207 AddControls(hWnd); |
203 EnumChildWindows(hWnd, (WNDENUMPROC)SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT)); | 208 EnumChildWindows(hWnd, (WNDENUMPROC)SetFont, (LPARAM)GetStockObject(DEFAULT_GUI_FONT)); |