Mercurial > msvpvf
comparison src/gui.c @ 68:207684d44b54
gui.c: Add drag and drop support
Utilizes the old Win 3.1 API for it, it does everything I need it to do
| author | Paper <mrpapersonic@gmail.com> |
|---|---|
| date | Wed, 04 Jan 2023 21:54:22 -0500 |
| parents | a2e979245441 |
| children | 79a35af2cb56 |
comparison
equal
deleted
inserted
replaced
| 67:0902a957d9b0 | 68:207684d44b54 |
|---|---|
| 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 * SOFTWARE. | 23 * SOFTWARE. |
| 24 **/ | 24 **/ |
| 25 #include <stdio.h> | 25 #include <stdio.h> |
| 26 #include <windows.h> | 26 #include <windows.h> |
| 27 #include <shellapi.h> | |
| 28 #include <shlwapi.h> | |
| 27 #include <stdint.h> | 29 #include <stdint.h> |
| 28 #include <stdbool.h> | 30 #include <stdbool.h> |
| 29 #include <commdlg.h> | 31 #include <commdlg.h> |
| 30 #include "../include/common.h" | 32 #include "../include/common.h" |
| 31 #define _WIN32_WINNT 0x0400 | 33 #define _WIN32_WINNT 0x0400 |
| 44 int16_t version = 13; | 46 int16_t version = 13; |
| 45 enum types { | 47 enum types { |
| 46 vf, | 48 vf, |
| 47 veg | 49 veg |
| 48 } type; | 50 } type; |
| 49 char* file_name = " "; | 51 char file_name[257] = {'\0'}; |
| 50 | 52 |
| 51 void display_file(char* path) { | 53 void display_file(char* path) { |
| 52 /* Read the file to memory */ | 54 /* Read the file to memory */ |
| 53 FILE* file; | 55 FILE* file; |
| 54 file = fopen(path, "rb"); | 56 file = fopen(path, "rb"); |
| 55 fseek(file, 0x46, SEEK_SET); | 57 fseek(file, 0x46, SEEK_SET); |
| 56 int f_version = fgetc(file); | 58 int f_version = fgetc(file)+1; |
| 57 fseek(file, 0x18, SEEK_SET); | 59 fseek(file, 0x18, SEEK_SET); |
| 58 TCHAR p[32]; | 60 TCHAR p[32]; |
| 59 switch (fgetc(file)) { | 61 switch (fgetc(file)) { |
| 60 case 0xEF: | 62 case 0xEF: |
| 61 snprintf(p, 32, "File version: %s %d", "VEGAS Pro", f_version); | 63 snprintf(p, 32, "File version: %s %d", "VEGAS Pro", f_version); |
| 65 break; | 67 break; |
| 66 default: | 68 default: |
| 67 snprintf(p, 32, "File version: %s %d", "Unknown", f_version); | 69 snprintf(p, 32, "File version: %s %d", "Unknown", f_version); |
| 68 break; | 70 break; |
| 69 } | 71 } |
| 70 printf("%s", p); | |
| 71 SendMessage(hWndVersion, WM_SETTEXT, (WPARAM)0, (LPARAM)p); | 72 SendMessage(hWndVersion, WM_SETTEXT, (WPARAM)0, (LPARAM)p); |
| 72 fclose(file); | 73 fclose(file); |
| 73 } | 74 } |
| 74 | 75 |
| 75 char* open_file(HWND hWnd) { | 76 char* open_file(HWND hWnd) { |
| 76 OPENFILENAME ofn; | 77 OPENFILENAME ofn; |
| 77 char filename[256]; | 78 char* filename = calloc(256, sizeof(char)); |
| 78 | 79 |
| 79 ZeroMemory(&ofn, OPENFILENAME_SIZE_VERSION_400); | 80 ZeroMemory(&ofn, OPENFILENAME_SIZE_VERSION_400); |
| 80 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; | 81 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; |
| 81 ofn.hwndOwner = hWnd; | 82 ofn.hwndOwner = hWnd; |
| 82 ofn.lpstrFile = filename; | 83 ofn.lpstrFile = filename; |
| 89 return " "; | 90 return " "; |
| 90 } | 91 } |
| 91 | 92 |
| 92 display_file(filename); | 93 display_file(filename); |
| 93 | 94 |
| 94 return strdup(filename); | 95 return filename; |
| 95 } | 96 } |
| 96 | 97 |
| 97 void save_file(HWND hWnd, char* input_file) { | 98 void save_file(HWND hWnd, char* input_file) { |
| 98 if (strcmp(input_file, " ") == 0) { | 99 if (strcmp(input_file, " ") == 0) { |
| 99 MessageBox(hWnd, | 100 MessageBox(hWnd, |
| 101 TEXT("Invalid input file!"), | 102 TEXT("Invalid input file!"), |
| 102 MB_ICONEXCLAMATION); | 103 MB_ICONEXCLAMATION); |
| 103 return; | 104 return; |
| 104 } | 105 } |
| 105 OPENFILENAME ofn; | 106 OPENFILENAME ofn; |
| 106 char output_file[256]; | 107 char output_file[256] = {'\0'}, *input_basename = strdup(input_file); |
| 108 PathStripPath(input_basename); | |
| 109 int amt_of_ch = snprintf(output_file, 256, "PRO_V%d_", version); | |
| 110 if (256-amt_of_ch > 0) | |
| 111 strncat(output_file, input_basename, 256-amt_of_ch); | |
| 107 | 112 |
| 108 ZeroMemory(&ofn, OPENFILENAME_SIZE_VERSION_400); | 113 ZeroMemory(&ofn, OPENFILENAME_SIZE_VERSION_400); |
| 109 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; | 114 ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; |
| 110 ofn.hwndOwner = hWnd; | 115 ofn.hwndOwner = hWnd; |
| 111 ofn.lpstrFile = output_file; | 116 ofn.lpstrFile = output_file; |
| 112 ofn.lpstrFile[0] = '\0'; | |
| 113 ofn.nMaxFile = 256; | 117 ofn.nMaxFile = 256; |
| 114 ofn.lpstrFilter = "Movie Studio project files\0*.vf\0VEGAS Pro project files\0*.veg\0All files\0*.*\0"; | 118 ofn.lpstrFilter = "Movie Studio project files\0*.vf\0VEGAS Pro project files\0*.veg\0All files\0*.*\0"; |
| 115 ofn.nFilterIndex = (int)type+1; | 119 ofn.nFilterIndex = (int)type+1; |
| 116 | 120 |
| 117 if (GetSaveFileName(&ofn) == 0) { | 121 if (GetSaveFileName(&ofn) == 0) { |
| 125 FILE* output = fopen(output_file, "r+b"); | 129 FILE* output = fopen(output_file, "r+b"); |
| 126 if (output == NULL) { | 130 if (output == NULL) { |
| 127 MessageBox(hWnd, TEXT("Failed to save project file!"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION); | 131 MessageBox(hWnd, TEXT("Failed to save project file!"), TEXT("Saving project failed!"), MB_ICONEXCLAMATION); |
| 128 return; | 132 return; |
| 129 } | 133 } |
| 134 | |
| 130 unsigned char magic_veg[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; | 135 unsigned char magic_veg[] = {0xEF, 0x29, 0xC4, 0x46, 0x4A, 0x90, 0xD2, 0x11, 0x87, 0x22, 0x00, 0xC0, 0x4F, 0x8E, 0xDB, 0x8A}; |
| 131 unsigned char magic_vf[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; | 136 unsigned char magic_vf[] = {0xF6, 0x1B, 0x3C, 0x53, 0x35, 0xD6, 0xF3, 0x43, 0x8A, 0x90, 0x64, 0xB8, 0x87, 0x23, 0x1F, 0x7F}; |
| 132 | 137 |
| 133 set_data(type == veg ? magic_veg : magic_vf, version, output); | 138 set_data(type == veg ? magic_veg : magic_vf, version-1, output); |
| 134 | 139 |
| 135 fclose(output); | 140 fclose(output); |
| 136 } | 141 } |
| 137 | 142 |
| 138 void AddControls(HWND hWnd) { | 143 void AddControls(HWND hWnd) { |
| 139 /* Versions */ | 144 /* Versions */ |
| 140 hWndComboBox = CreateWindow("ComboBox", NULL, | 145 hWndComboBox = CreateWindow("ComboBox", NULL, |
| 141 CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_VSCROLL, | 146 CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_VISIBLE | WS_OVERLAPPED | WS_VSCROLL, |
| 142 (int)((225 - 50)/2), 30, 50, 200, | 147 (int)((225 - 50)/2), 30, 50, 200, |
| 143 hWnd, (HMENU)COMBOBOX, NULL, NULL); /** | 148 hWnd, (HMENU)COMBOBOX, NULL, NULL); |
| 144 * I don't understand what half of | 149 |
| 145 * these arguments are for, so chances | |
| 146 * are that you don't either. | |
| 147 **/ | |
| 148 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"), | 150 TCHAR versions[][10] = {TEXT("8"), TEXT("9"), TEXT("10"), |
| 149 TEXT("11"), TEXT("12"), TEXT("13"), | 151 TEXT("11"), TEXT("12"), TEXT("13"), |
| 150 TEXT("14"), TEXT("15"), TEXT("16"), | 152 TEXT("14"), TEXT("15"), TEXT("16"), |
| 151 TEXT("17"), TEXT("18"), TEXT("19")}; | 153 TEXT("17"), TEXT("18"), TEXT("19")}; |
| 152 | 154 |
| 187 if (LOWORD(wParam) == LISTBOX) | 189 if (LOWORD(wParam) == LISTBOX) |
| 188 type = SendMessage((HWND) lParam, (UINT) LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); | 190 type = SendMessage((HWND) lParam, (UINT) LB_GETCURSEL, (WPARAM) 0, (LPARAM) 0); |
| 189 } | 191 } |
| 190 switch(wParam) { | 192 switch(wParam) { |
| 191 case OPEN_FILE_BUTTON: | 193 case OPEN_FILE_BUTTON: |
| 192 file_name = open_file(hWnd); | 194 strncpy(file_name, open_file(hWnd), 256); |
| 193 case COMBOBOX: | 195 case COMBOBOX: |
| 194 case LISTBOX: | 196 case LISTBOX: |
| 195 case VERSION: | 197 case VERSION: |
| 196 break; | 198 break; |
| 197 case SAVE_FILE_BUTTON: | 199 case SAVE_FILE_BUTTON: |
| 204 break; | 206 break; |
| 205 } | 207 } |
| 206 case WM_DESTROY: | 208 case WM_DESTROY: |
| 207 PostQuitMessage(0); | 209 PostQuitMessage(0); |
| 208 break; | 210 break; |
| 211 case WM_DROPFILES: | |
| 212 /* Drag and drop support */ | |
| 213 HDROP hDrop = (HDROP)wParam; | |
| 214 DragQueryFile(hDrop, 0, file_name, 256); | |
| 215 display_file(file_name); | |
| 216 break; | |
| 209 default: | 217 default: |
| 210 return DefWindowProc(hWnd, msg, wParam, lParam); | 218 return DefWindowProc(hWnd, msg, wParam, lParam); |
| 211 } | 219 } |
| 212 return false; | 220 return false; |
| 213 } | 221 } |
| 221 wc.lpszClassName = "msvpvf"; | 229 wc.lpszClassName = "msvpvf"; |
| 222 wc.lpfnWndProc = WindowProcedure; | 230 wc.lpfnWndProc = WindowProcedure; |
| 223 | 231 |
| 224 if (!RegisterClass(&wc)) return -1; | 232 if (!RegisterClass(&wc)) return -1; |
| 225 | 233 |
| 226 CreateWindow(TEXT("msvpvf"), TEXT("Movie Studio / Vegas Pro version spoofer"), WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, 100, 100, 225, 200, NULL, NULL, hInstance, NULL); | 234 CreateWindowEx(WS_EX_ACCEPTFILES, TEXT("msvpvf"), TEXT("Movie Studio / Vegas Pro version spoofer"), WS_OVERLAPPED | WS_VISIBLE | WS_MINIMIZEBOX | WS_SYSMENU, 100, 100, 225, 200, NULL, NULL, hInstance, NULL); |
| 227 | 235 |
| 228 MSG msg = {0}; | 236 MSG msg = {0}; |
| 229 | 237 |
| 230 while (GetMessage(&msg, NULL, 0, 0)) { | 238 while (GetMessage(&msg, NULL, 0, 0)) { |
| 231 TranslateMessage(&msg); | 239 TranslateMessage(&msg); |
