summaryrefslogtreecommitdiff
path: root/gui/win32/src/main.c
blob: b7f7603efe72a857c0b0f6b17a510af063a1b58c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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;
}