From 239cd62103d617f0b2a9d58527843417a0db6ab4 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Mon, 9 Mar 2026 14:48:15 +0800 Subject: Add Win32 GUI for butck_gui.exe --- gui/win32/.gitignore | 57 ++++++++++++++++++++++++ gui/win32/CMakeLists.txt | 30 +++++++++++++ gui/win32/cbuild.ps1 | 20 +++++++++ gui/win32/scripts/_entry.ps1 | 91 ++++++++++++++++++++++++++++++++++++++ gui/win32/scripts/build.ps1 | 87 +++++++++++++++++++++++++++++++++++++ gui/win32/scripts/clean.ps1 | 15 +++++++ gui/win32/scripts/run.ps1 | 10 +++++ gui/win32/src/butck_gui.rc | 14 ++++++ gui/win32/src/main.c | 101 +++++++++++++++++++++++++++++++++++++++++++ gui/win32/src/resource.h | 11 +++++ 10 files changed, 436 insertions(+) create mode 100644 gui/win32/.gitignore create mode 100644 gui/win32/CMakeLists.txt create mode 100644 gui/win32/cbuild.ps1 create mode 100644 gui/win32/scripts/_entry.ps1 create mode 100644 gui/win32/scripts/build.ps1 create mode 100644 gui/win32/scripts/clean.ps1 create mode 100644 gui/win32/scripts/run.ps1 create mode 100644 gui/win32/src/butck_gui.rc create mode 100644 gui/win32/src/main.c create mode 100644 gui/win32/src/resource.h diff --git a/gui/win32/.gitignore b/gui/win32/.gitignore new file mode 100644 index 0000000..3ce4fb3 --- /dev/null +++ b/gui/win32/.gitignore @@ -0,0 +1,57 @@ +build/ +build*/ +*/build/ +*/build*/ + +CMakeCache.txt +CMakeFiles/ +cmake_install.cmake +Makefile +CMakeScripts/ +CTestTestfile.cmake +*.cbp +*.cmake + +*.exe +*.ilk +*.obj +*.pdb +*.user +*.aps +*.ncb +*.suo +*.tlog +*.log +*.idb +*.pch +*.res +*.sbr +*.manifest +*.exp +*.lib +*.dll +*.dll.a +*.a +*.o +*.out +*.app +*.dylib +*.framework + +.vscode/ +.idea/ +*.sln +*.vcxproj +*.vcxproj.filters +*.vcxproj.user +*.sdf +*.opensdf +*.db + +bin/ +Debug/ +Release/ +x64/ +x86/ + +.clangd diff --git a/gui/win32/CMakeLists.txt b/gui/win32/CMakeLists.txt new file mode 100644 index 0000000..2fc5f79 --- /dev/null +++ b/gui/win32/CMakeLists.txt @@ -0,0 +1,30 @@ +cmake_minimum_required(VERSION 3.10) +project(butck_gui VERSION 1.0.0 LANGUAGES C RC) + +set(CMAKE_C_STANDARD 11) +set(CMAKE_C_STANDARD_REQUIRED ON) + +enable_language(RC) + +add_executable(butck_gui WIN32 + src/main.c + src/butck_gui.rc +) + +if(WIN32) + target_compile_definitions(butck_gui PRIVATE + UNICODE + _UNICODE + _WIN32_WINNT=0x0A00 + ) + + target_link_libraries(butck_gui + user32 + gdi32 + comctl32 + ) +endif() + +set_target_properties(butck_gui PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin +) diff --git a/gui/win32/cbuild.ps1 b/gui/win32/cbuild.ps1 new file mode 100644 index 0000000..85a7d54 --- /dev/null +++ b/gui/win32/cbuild.ps1 @@ -0,0 +1,20 @@ +function Build { + & "$PSScriptRoot\scripts\build.ps1" +} + +function Clean { + & "$PSScriptRoot\scripts\clean.ps1" +} + +function Run { + & "$PSScriptRoot\scripts\run.ps1" +} + +switch ($args[0]) { + "rebuild" { Build } + "clean" { Clean } + "run" { Build; Run } + default { + Write-Host "Usage: .\mgr.ps1 [build|clean|run]" + } +} diff --git a/gui/win32/scripts/_entry.ps1 b/gui/win32/scripts/_entry.ps1 new file mode 100644 index 0000000..1d49e46 --- /dev/null +++ b/gui/win32/scripts/_entry.ps1 @@ -0,0 +1,91 @@ +$pathsToPreserve = @() +$originalPath = $env:PATH -split ';' +foreach ($pathEntry in $originalPath) { + if ($pathEntry -match 'CMake|Python|Git|System32|WindowsApps') { + $pathsToPreserve += $pathEntry + } +} + +Get-ChildItem env: | Where-Object { $_.Name -match "^INCLUDE$|^LIB$|^LIBPATH$" } | ForEach-Object { + Remove-Item "env:\$($_.Name)" +} + +$env:Path = $pathsToPreserve -join ';' + +$vcTools = "C:\Program Files\Microsoft Visual Studio\18\Community\VC\Tools\MSVC\14.50.35717" +$vcHost = "Hostx64\x64" + +$clPath = "$vcTools\bin\$vcHost" +$env:Path = "$clPath;$env:Path" + +$sdkBase = "C:\Program Files (x86)\Windows Kits\10" +$sdkVersions = Get-ChildItem "$sdkBase\Include" -Directory | + Where-Object { $_.Name -match "^\d+\.\d+" } | + Sort-Object Name -Descending + +if ($sdkVersions) { + $latestSdk = $sdkVersions[0].Name + + $sdkBin = "$sdkBase\bin\$latestSdk\x64" + $env:Path = "$sdkBin;$env:Path" + + $includePaths = @( + "$vcTools\include", + "$sdkBase\Include\$latestSdk\um", + "$sdkBase\Include\$latestSdk\shared", + "$sdkBase\Include\$latestSdk\ucrt" + ) + $env:INCLUDE = ($includePaths -join ';') + + $libPaths = @( + "$vcTools\lib\x64", + "$sdkBase\Lib\$latestSdk\um\x64", + "$sdkBase\Lib\$latestSdk\ucrt\x64" + ) + $env:LIB = ($libPaths -join ';') + + $env:LIBPATH = "$vcTools\lib\x64;$sdkBase\Lib\$latestSdk\um\x64" +} else { + Write-Host "Warning: Using generic SDK path" -ForegroundColor Yellow + $env:Path = "$sdkBase\bin\x64;$env:Path" + $env:INCLUDE = "$vcTools\include" + $env:LIB = "$vcTools\lib\x64" +} + +$libFiles = @( + "$vcTools\lib\x64\MSVCRTD.lib", + "$vcTools\lib\x64\MSVCRT.lib" +) + +foreach ($lib in $libFiles) { + if (-not (Test-Path $lib)) { + Write-Host "$(Split-Path $lib -Leaf)" -ForegroundColor Red + } +} + +# Generate .clangd configuration file +$clangdContent = @" +CompileFlags: + CompilationDatabase: build/ + Add: + - -I$sdkBase\Include\$latestSdk\um + - -I$sdkBase\Include\$latestSdk\shared + - -I$sdkBase\Include\$latestSdk\ucrt + - -I$vcTools\include + - -I`${workspaceFolder}/include + Remove: [] + +Diagnostics: + ClangTidy: + Add: + - "*" + Remove: + - modernize-use-trailing-return-type + UnusedIncludes: Strict + +Index: + Background: Build +"@ + +$clangdPath = "..\.clangd" +$clangdContent | Out-File -FilePath $clangdPath -Encoding UTF8 diff --git a/gui/win32/scripts/build.ps1 b/gui/win32/scripts/build.ps1 new file mode 100644 index 0000000..a5c01e5 --- /dev/null +++ b/gui/win32/scripts/build.ps1 @@ -0,0 +1,87 @@ +$originalLocation = Get-Location +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $scriptPath + +. $scriptPath\_entry.ps1 + +$generator = "" +$arch = "x64" + +$vsPaths = @( + "C:\Program Files\Microsoft Visual Studio\2022\Community", + "C:\Program Files\Microsoft Visual Studio\2022\Professional", + "C:\Program Files\Microsoft Visual Studio\2022\Enterprise", + "C:\Program Files\Microsoft Visual Studio\2022\BuildTools", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise", + "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise", + "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" +) + +foreach ($path in $vsPaths) { + if (Test-Path $path) { + if ($path -match "2022") { + $generator = "Visual Studio 17 2022" + } elseif ($path -match "2019") { + $generator = "Visual Studio 16 2019" + } elseif ($path -match "2017") { + $generator = "Visual Studio 15 2017" + } + break + } +} + +if ([string]::IsNullOrEmpty($generator)) { + if (Get-Command ninja -ErrorAction SilentlyContinue) { + $generator = "Ninja" + } + elseif (Get-Command nmake -ErrorAction SilentlyContinue) { + $generator = "NMake Makefiles" + } + elseif (Get-Command mingw32-make -ErrorAction SilentlyContinue) { + $generator = "MinGW Makefiles" + } + else { + Write-Host "No suitable generator found. Please install Visual Studio or another build system." -ForegroundColor Red + exit 1 + } +} + +if (!(Test-Path -Path "..\build")) { + New-Item -ItemType Directory -Path "..\build" | Out-Null +} +Set-Location "..\build" + +if ($generator -match "Visual Studio") { + if ($generator -match "Visual Studio 15 2017") { + cmake .. -G "$generator" -A $arch + } else { + cmake .. -G "$generator" -A $arch + } +} else { + cmake .. -G "$generator" +} + +if ($LASTEXITCODE -ne 0) { + Write-Host "CMake configuration failed!" -ForegroundColor Red + Set-Location $originalLocation + exit 1 +} + +if ($generator -match "Visual Studio") { + cmake --build . --config Release +} else { + cmake --build . +} + +if ($LASTEXITCODE -ne 0) { + Write-Host "Build failed!" -ForegroundColor Red + Set-Location $originalLocation + exit 1 +} + +Set-Location $originalLocation diff --git a/gui/win32/scripts/clean.ps1 b/gui/win32/scripts/clean.ps1 new file mode 100644 index 0000000..59d9593 --- /dev/null +++ b/gui/win32/scripts/clean.ps1 @@ -0,0 +1,15 @@ +$originalLocation = Get-Location +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $scriptPath + +if (!(Test-Path -Path "..\build")) { + Set-Location $originalLocation + exit +} + +Remove-Item "..\build" -Recurse -Force -ErrorAction SilentlyContinue +if (Test-Path -Path "..\.clangd") { + Remove-Item "..\.clangd" -Recurse -Force -ErrorAction SilentlyContinue +} + +Set-Location $originalLocation diff --git a/gui/win32/scripts/run.ps1 b/gui/win32/scripts/run.ps1 new file mode 100644 index 0000000..a8f50e8 --- /dev/null +++ b/gui/win32/scripts/run.ps1 @@ -0,0 +1,10 @@ +$originalLocation = Get-Location +$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path +Set-Location $scriptPath + +$exePath = "..\build\bin\butck_gui.exe" +if (Test-Path $exePath) { + & $exePath +} + +Set-Location $originalLocation diff --git a/gui/win32/src/butck_gui.rc b/gui/win32/src/butck_gui.rc new file mode 100644 index 0000000..a609d9d --- /dev/null +++ b/gui/win32/src/butck_gui.rc @@ -0,0 +1,14 @@ +#include "windows.h" +#include "resource.h" + +IDR_MAINMENU MENU +BEGIN + POPUP "Files(&F)" + BEGIN + MENUITEM "Exit(&X)", IDM_EXIT + END + POPUP "Help(&H)" + BEGIN + MENUITEM "About(&A)...", IDM_ABOUT + END +END 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 + +// 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; +} diff --git a/gui/win32/src/resource.h b/gui/win32/src/resource.h new file mode 100644 index 0000000..d28d2b2 --- /dev/null +++ b/gui/win32/src/resource.h @@ -0,0 +1,11 @@ +#pragma once + +#define IDR_MAINMENU 101 + +#define IDM_EXIT 1001 +#define IDM_ABOUT 1002 + +#define IDC_MYBUTTON 2001 + +#define IDC_SELECT_FILE 1003 +#define IDC_STATUS_LABEL 1004 -- cgit