diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-03-09 14:48:15 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-03-09 14:53:36 +0800 |
| commit | 239cd62103d617f0b2a9d58527843417a0db6ab4 (patch) | |
| tree | 2566d5ce8a5bfae7b92e7c83c011655753b83a0e /gui/win32/src/main.c | |
| parent | e02921ae75d41253406834bd7e214c3c8dec6f9b (diff) | |
Add Win32 GUI for butck_gui.exe
Diffstat (limited to 'gui/win32/src/main.c')
| -rw-r--r-- | gui/win32/src/main.c | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/gui/win32/src/main.c b/gui/win32/src/main.c new file mode 100644 index 0000000..b7f7603 --- /dev/null +++ b/gui/win32/src/main.c @@ -0,0 +1,101 @@ +#include "resource.h" +#include <windows.h> + +// Global variables +static HINSTANCE hInst; +const wchar_t CLASS_NAME[] = L"ButchunkerWindow"; + +// Function declarations +LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, + PWSTR pCmdLine, int nCmdShow) +{ + (void)hPrevInstance; // Unused parameter + (void)pCmdLine; // Unused parameter + + hInst = hInstance; + + // Register window class + WNDCLASSW windowClass = {0}; + windowClass.lpfnWndProc = WindowProc; + windowClass.hInstance = hInstance; + windowClass.lpszClassName = CLASS_NAME; + windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); + windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); + windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); + windowClass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU); + + if (!RegisterClassW(&windowClass)) { + MessageBoxW(NULL, L"Window class registration failed!", L"Error", MB_ICONERROR); + return 0; + } + + const int WINDOW_WIDTH = 800; + const int WINDOW_HEIGHT = 600; + + // Create window + HWND hwnd = CreateWindowExW( + 0, // Extended window style + CLASS_NAME, // Window class name + L"Butchunker - File Chunking Tool", // Window title + WS_OVERLAPPEDWINDOW, // Window style + CW_USEDEFAULT, CW_USEDEFAULT, // Position + WINDOW_WIDTH, WINDOW_HEIGHT, // Size + NULL, // Parent window + NULL, // Menu + hInstance, // Instance handle + NULL // Additional data + ); + + if (hwnd == NULL) { + MessageBoxW(NULL, L"Window creation failed!", L"Error", MB_ICONERROR); + return 0; + } + + // Show window + ShowWindow(hwnd, nCmdShow); + UpdateWindow(hwnd); + + // Message loop + MSG msg = {0}; + while (GetMessage(&msg, NULL, 0, 0)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return 0; +} + +// Window procedure function +LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_COMMAND: { + int wmId = LOWORD(wParam); + + switch (wmId) { + case IDM_EXIT: + DestroyWindow(hwnd); + break; + + case IDM_ABOUT: + MessageBoxW(hwnd, L"Butchunker - File Chunking Tool\nVersion 1.0.0", L"About", MB_OK); + break; + + default: + return DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + break; + } + + case WM_DESTROY: + PostQuitMessage(0); + return 0; + + default: + return DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + + return 0; +} |
