Mercurial > msvpvf
comparison src/gui.c @ 47:7cb4ca7cf257
Use a common.c file to hold concurrent functions
Also I fixed that 1.4 KB bug I think
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 21 May 2022 18:41:54 -0400 |
parents | cd50c59286be |
children | 0f6c604b6863 |
comparison
equal
deleted
inserted
replaced
46:7cb9fad3f5ee | 47:7cb4ca7cf257 |
---|---|
25 #include <stdio.h> | 25 #include <stdio.h> |
26 #include <windows.h> | 26 #include <windows.h> |
27 #include <stdint.h> | 27 #include <stdint.h> |
28 #include <stdbool.h> | 28 #include <stdbool.h> |
29 #include <commdlg.h> | 29 #include <commdlg.h> |
30 #include "../include/common.h" | |
30 #define _WIN32_WINNT 0x0400 | 31 #define _WIN32_WINNT 0x0400 |
31 #define ARRAYSIZE(a) \ | 32 #define ARRAYSIZE(a) \ |
32 sizeof(a)/sizeof(a[0]) | 33 sizeof(a)/sizeof(a[0]) |
33 #define OPEN_FILE_BUTTON 0 | 34 #define OPEN_FILE_BUTTON 0 |
34 #define COMBOBOX 1 | 35 #define COMBOBOX 1 |
44 vf, | 45 vf, |
45 veg | 46 veg |
46 } type; | 47 } type; |
47 char* file_name = " "; | 48 char* file_name = " "; |
48 | 49 |
49 void set_data(unsigned char magic[], uint16_t version, FILE* target) { | |
50 int i; | |
51 fseek(target, 0x46, SEEK_SET); | |
52 fputc(version, target); | |
53 for (i=0; i<=sizeof(*magic); ++i) { | |
54 fseek(target, 0x18+i, SEEK_SET); | |
55 fputc(magic[i], target); | |
56 } | |
57 } | |
58 | |
59 int copy_file(char* source_file, char* target_file) { | |
60 /* Copy a file */ | |
61 FILE *source, *target; | |
62 | |
63 source = fopen(source_file, "rb"); | |
64 if (source == NULL) return 1; | |
65 target = fopen(target_file, "wb"); | |
66 if (target == NULL) { | |
67 fclose(source); | |
68 return 1; | |
69 } | |
70 | |
71 size_t n, m; | |
72 unsigned char buff[8192]; | |
73 do { | |
74 n = fread(buff, 1, sizeof(buff), source); | |
75 if (n) m = fwrite(buff, 1, n, target); | |
76 else m = 0; | |
77 } while ((n > 0) && (n == m)); | |
78 | |
79 fclose(target); | |
80 fclose(source); | |
81 return 0; | |
82 } | |
83 | 50 |
84 void display_file(char* path) { | 51 void display_file(char* path) { |
85 /* Read the file to memory */ | 52 /* Read the file to memory */ |
86 FILE* file; | 53 FILE* file; |
87 file = fopen(path, "rb"); | 54 file = fopen(path, "rb"); |
175 hWnd, (HMENU)COMBOBOX, NULL, NULL); /** | 142 hWnd, (HMENU)COMBOBOX, NULL, NULL); /** |
176 * I don't understand what half of | 143 * I don't understand what half of |
177 * these arguments are for, so chances | 144 * these arguments are for, so chances |
178 * are that you don't either. | 145 * are that you don't either. |
179 **/ | 146 **/ |
180 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"), | 147 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"), |
181 TEXT("11"), TEXT("12"), TEXT("13"), | 148 TEXT("11"), TEXT("12"), TEXT("13"), |
182 TEXT("14"), TEXT("15"), TEXT("16"), | 149 TEXT("14"), TEXT("15"), TEXT("16"), |
183 TEXT("17"), TEXT("18"), TEXT("19")}; | 150 TEXT("17"), TEXT("18"), TEXT("19")}; |
184 | 151 |
185 TCHAR A[16]; | |
186 | |
187 /** | |
188 * Here we can't just use a for loop | |
189 * and cast all of those to `TEXT()`. | |
190 * Why? I don't know. My brain is too | |
191 * small to figure it out. | |
192 **/ | |
193 memset(&A,0,sizeof(A)); | |
194 int i = 0; | 152 int i = 0; |
195 for (i = 0; i <= 11; i++) { | 153 for (i = 0; i < ARRAYSIZE(versions); i++) { |
196 strncpy((TCHAR*)A, (TCHAR*)versions[i], ARRAYSIZE(A)); | 154 SendMessage(hWndComboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)versions[i]); |
197 SendMessage(hWndComboBox, (UINT)CB_ADDSTRING, (WPARAM)0, (LPARAM)A); | |
198 } | 155 } |
199 SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)3, (LPARAM)0); | 156 SendMessage(hWndComboBox, CB_SETCURSEL, (WPARAM)3, (LPARAM)0); |
200 /* Open File */ | 157 /* Open File */ |
201 HWND open_button = CreateWindowA("Button", "Open", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 5, 50, 20, hWnd, (HMENU)OPEN_FILE_BUTTON, NULL, NULL); | 158 HWND open_button = CreateWindowA("Button", "Open", WS_VISIBLE | WS_CHILD, (int)((225 - 50)/2), 5, 50, 20, hWnd, (HMENU)OPEN_FILE_BUTTON, NULL, NULL); |
202 /* Type */ | 159 /* Type */ |