新星项目Code date creation

目录

hi,我带来最新一款数据生成器Code date creation。

大家能支持点赞下吗?

开发团队

https://www.luogu.com.cn/team/129680

https://gitcode.com/starryfast

最新Acgo:https://www.acgo.cn/team/2009944681308327936

介绍

介绍

Code-date-creation 是一款由 CDCluogu 团队研发的新一代 C++ 图形化数据生成器。该工具可以帮助用户在洛谷网站、acgo网站等平台上生成测试数据。

该工具包含一个安装包,用户可以将其安装在计算机上。安装完成后,用户可以通过运行主体exe文件来使用它。

Code-date-creation 的主要功能是为 C++ 编程者提供一个方便的工具,用于生成各种类型的测试数据。这些数据可以用于测试和验证 C++ 程序的功能和性能。

该工具的使用非常简单。首先,用户需要将 Code-date-creation 安装到计算机上。然后,通过运行主程序,用户可以选择要生成的数据类型,如数组、字符串、函数等。接下来,用户可以根据需要进行配置,例如设置数据的范围、长度等。最后,用户点击"生成"按钮,即可生成所需的测试数据。

总之,Code-date-creation 是一个功能强大且易于使用的 C++ 静态数据生成器,可以帮助用户轻松生成各种类型的测试数据。又CDCluogu研发出的,新一代C++静态数据生成器,包含安装包,已经主体exe,帮助你在洛谷网站或acgo网站等生成测试数据,cpp已公开。

此介绍摘自此网站

功能介绍

可帮助你快速编译数据,支持随机数据和自编译模式,界面图形化。

只要你有AC代码就能造!

快速帮助新手上手。

5.0.0新功能

我们支持颜色更改,换一下主题也不错,如果想换回来,可以点默认颜色呢,此软件保留之前颜色。

版权问题

以下是本次工作人员。

starryfast 主策划(编写者兼宣传)

也就是我。

StellarCode bug测试

pjz1061065454 360安全测试

skysunrise_c颜色测试

chfqwq全科测试

我们开发团队仅有这些人,请注意辨别。

市面盗版不要下载,可能中病毒。

本次使用 VSCode 编译,主要为**C++**代码编译。

软件要求

本次软件有安装包,需要您的电脑有 g++。

没有安装包有自带 g++,不过自带 g++ 仅仅支持 C++11。

请确保您的电脑空间充足。

下载

下载网站http://b-bu.cn/b01d70edvg ,密码CDC500

代码仓

github:https://github.com/starryfast/Code-date-creation

gitcode https://gitcode.com/starryfast/Codedatecreation

招募

现在招一位bug检测和宣传。

有意者联系作者。

QQ:272215275

邮箱:272215275@qq.com

联系同意后加入。

https://www.luogu.com.cn/team/129680

https://gitcode.com/starryfast

详细解说

https://www.bilibili.com/video/BV1jzJp6CEG8/?spm_id_from=888.80997.embed_other.whitelist&bvid=BV1jzJp6CEG8

在线源码

cpp 复制代码
#define _CRT_SECURE_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x0601
#include <windows.h>
#include <commctrl.h>
#include <commdlg.h>
#include <shlobj.h>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <io.h>

#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "comdlg32.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "gdi32.lib")

using namespace std;

HWND g_hMainWnd;
HINSTANCE g_hInst;
HFONT g_hFontNormal, g_hFontBold;

COLORREF g_textColor = RGB(0, 0, 0);
COLORREF g_bgColor = RGB(255, 255, 255);

#define IDC_EDIT_START       101
#define IDC_EDIT_END         102
#define IDC_COMBO_TYPE       103
#define IDC_EDIT_RANGE1      104
#define IDC_EDIT_RANGE2      105
#define IDC_EDIT_STRLEN      106
#define IDC_EDIT_COUNT       107
#define IDC_CHECK_WRITE      108
#define IDC_BUTTON_GEN       109
#define IDC_EDIT_CPP_PATH    111
#define IDC_BUTTON_BROWSE    112
#define IDC_STATIC_STATUS    118
#define IDC_STATIC_AUTHOR    119
#define IDC_EDIT_VAR_TEXT    120
#define IDC_EDIT_GPP_PATH    121
#define IDC_BUTTON_GPP_BROWSE 122
#define IDC_BUTTON_GPP_AUTO   123
#define IDC_EDIT_OUTDIR      124
#define IDC_BUTTON_OUTDIR_BROWSE 125

#define IDC_RADIO_MODE_RANDOM   130
#define IDC_RADIO_MODE_MANUAL   131
#define IDC_EDIT_MANUAL_INNAME  132
#define IDC_EDIT_MANUAL_INCONTENT 133
#define IDC_BUTTON_MANUAL_SAVEIN  136

#define IDC_BUTTON_UNIFIED_COMPILE 140
#define IDC_BUTTON_COLOR_SETTING   141
#define IDC_BUTTON_DEFAULT_COLOR   142

#define IDC_STATIC_START_LABEL   201
#define IDC_STATIC_END_LABEL     202
#define IDC_STATIC_TYPE_LABEL    203
#define IDC_STATIC_RANGE_LABEL   204
#define IDC_STATIC_RANGESEP      205
#define IDC_STATIC_COUNT_LABEL   206
#define IDC_STATIC_VAR_LABEL     207
#define IDC_STATIC_OUTDIR_LABEL  208
#define IDC_STATIC_MANUAL_LABEL1 209
#define IDC_STATIC_MANUAL_LABEL2 210

struct ExtraVar { wstring name, value; };

int g_baseClientWidth = 950;
int g_baseClientHeight = 850;
int g_currentMode = 0;
wstring g_outputDir;

// 随机数函数
int randomInt(int min, int max) { return min + rand() % (max - min + 1); }
long long randomBetween(long long a, long long b) {
    if (a > b) swap(a, b);
    unsigned long long range = (unsigned long long)(b - a) + 1;
    unsigned long long r = ((unsigned long long)rand() << 30) | ((unsigned long long)rand() << 15) | (unsigned long long)rand();
    return a + (long long)(r % range);
}
wstring randomString(int length, const wstring& charset) {
    wstring result;
    result.reserve(length);
    for (int i = 0; i < length; ++i) result += charset[rand() % charset.size()];
    return result;
}

wstring GetDesktopPath() {
    wchar_t path[MAX_PATH];
    if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_DESKTOP, NULL, SHGFP_TYPE_CURRENT, path)))
        return wstring(path);
    return L".";
}

vector<ExtraVar> ParseExtraVars(HWND hEdit) {
    vector<ExtraVar> result;
    int len = GetWindowTextLengthW(hEdit);
    if (len == 0) return result;
    wchar_t* buf = new wchar_t[len + 2];
    GetWindowTextW(hEdit, buf, len + 2);
    wstringstream ss(buf);
    wstring line;
    while (getline(ss, line)) {
        if (line.empty()) continue;
        size_t eq = line.find(L'=');
        if (eq == wstring::npos) {
            size_t sp = line.find_first_of(L" \t");
            if (sp != wstring::npos) {
                ExtraVar ev;
                ev.name = line.substr(0, sp);
                ev.value = line.substr(sp + 1);
                result.push_back(ev);
            }
            else {
                ExtraVar ev;
                ev.name = line;
                ev.value = L"";
                result.push_back(ev);
            }
        }
        else {
            ExtraVar ev;
            ev.name = line.substr(0, eq);
            ev.value = line.substr(eq + 1);
            result.push_back(ev);
        }
    }
    delete[] buf;
    return result;
}

bool GenerateInputFiles(int start, int end, int dataType, long long range1, long long range2, int strLen, int countPerFile, bool writeCount, const vector<ExtraVar>& vars) {
    if (g_outputDir.empty()) g_outputDir = GetDesktopPath();
    if (dataType == 2) {
        unsigned long long rangeSize = (range2 >= range1) ? (unsigned long long)(range2 - range1 + 1) : 0;
        if ((unsigned long long)countPerFile > rangeSize) return false;
    }
    const wstring lowerChars = L"abcdefghijklmnopqrstuvwxyz";
    const wstring upperChars = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    const wstring mixedChars = L"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    for (int i = start; i <= end; ++i) {
        wchar_t fullPath[MAX_PATH];
        swprintf(fullPath, MAX_PATH, L"%s\\%d.in", g_outputDir.c_str(), i);
        FILE* fp = _wfopen(fullPath, L"w");
        if (!fp) return false;
        for (size_t v = 0; v < vars.size(); ++v) {
            if (vars[v].value.empty()) fwprintf(fp, L"%s\n", vars[v].name.c_str());
            else fwprintf(fp, L"%s %s\n", vars[v].name.c_str(), vars[v].value.c_str());
        }
        if (writeCount) fwprintf(fp, L"%d\n", countPerFile);
        if (dataType <= 2) {
            if (dataType == 1) {
                for (int j = 0; j < countPerFile; ++j) fwprintf(fp, L"%lld ", randomBetween(range1, range2));
            }
            else {
                set<long long> used;
                while (used.size() < (size_t)countPerFile) used.insert(randomBetween(range1, range2));
                for (set<long long>::iterator it = used.begin(); it != used.end(); ++it) fwprintf(fp, L"%lld ", *it);
            }
        }
        else {
            const wstring* charset = (dataType == 3) ? &lowerChars : (dataType == 4) ? &upperChars : &mixedChars;
            for (int j = 0; j < countPerFile; ++j) fwprintf(fp, L"%s ", randomString(strLen, *charset).c_str());
        }
        fwprintf(fp, L"\n");
        fclose(fp);
    }
    return true;
}

bool FileExists(const wstring& path) { return _waccess(path.c_str(), 0) == 0; }

wstring FindGppInPath() {
    wchar_t* pathEnv = _wgetenv(L"PATH");
    if (!pathEnv) return L"";
    wstringstream ss(pathEnv);
    wstring dir;
    while (getline(ss, dir, L';')) {
        if (dir.empty()) continue;
        if (FileExists(dir + L"\\g++.exe")) return dir + L"\\g++.exe";
    }
    return L"";
}

void SearchGppInDir(const wstring& dir, int depth, vector<wstring>& results) {
    if (depth > 6 || dir.empty()) return;
    WIN32_FIND_DATAW fd;
    HANDLE hFind = FindFirstFileW((dir + L"\\*").c_str(), &fd);
    if (hFind == INVALID_HANDLE_VALUE) return;
    do {
        if (wcscmp(fd.cFileName, L".") == 0 || wcscmp(fd.cFileName, L"..") == 0) continue;
        wstring fullPath = dir + L"\\" + fd.cFileName;
        if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
            if (_wcsicmp(fd.cFileName, L"Windows") == 0 ||
                _wcsicmp(fd.cFileName, L"System32") == 0 ||
                _wcsicmp(fd.cFileName, L"WinSxS") == 0 ||
                _wcsicmp(fd.cFileName, L"$Recycle.Bin") == 0)
                continue;
            SearchGppInDir(fullPath, depth + 1, results);
        }
        else {
            if (_wcsicmp(fd.cFileName, L"g++.exe") == 0) {
                results.push_back(fullPath);
                break;
            }
        }
    } while (FindNextFileW(hFind, &fd));
    FindClose(hFind);
}

wstring AutoFindGpp() {
    wchar_t exePath[MAX_PATH];
    GetModuleFileNameW(NULL, exePath, MAX_PATH);
    wstring exeDir = exePath;
    size_t pos = exeDir.find_last_of(L"\\/");
    if (pos != wstring::npos) {
        exeDir = exeDir.substr(0, pos);
        if (FileExists(exeDir + L"\\g++.exe")) return exeDir + L"\\g++.exe";
        wstring tmp = exeDir + L"\\..\\mingw64\\bin\\g++.exe";
        if (FileExists(tmp)) return tmp;
        tmp = exeDir + L"\\..\\..\\mingw64\\bin\\g++.exe";
        if (FileExists(tmp)) return tmp;
    }

    wstring pathGpp = FindGppInPath();
    if (!pathGpp.empty()) return pathGpp;

    const wchar_t* commonPaths[] = {
        L"C:\\MinGW\\bin\\g++.exe", L"C:\\mingw64\\bin\\g++.exe",
        L"D:\\MinGW\\bin\\g++.exe", L"D:\\mingw64\\bin\\g++.exe",
        L"C:\\TDM-GCC-64\\bin\\g++.exe",
        L"C:\\Program Files\\mingw-w64\\mingw64\\bin\\g++.exe",
        L"C:\\Program Files\\CodeBlocks\\MinGW\\bin\\g++.exe",
        L"C:\\Dev-Cpp\\MinGW64\\bin\\g++.exe",
        L"C:\\RedPanda-Cpp\\mingw64\\bin\\g++.exe"
    };
    for (int i = 0; i < sizeof(commonPaths) / sizeof(commonPaths[0]); ++i)
        if (FileExists(commonPaths[i])) return wstring(commonPaths[i]);

    DWORD drives = GetLogicalDrives();
    vector<wstring> results;
    for (int i = 0; i < 26; ++i) {
        if (drives & (1 << i)) {
            wstring root = wstring(1, L'A' + i) + L":\\";
            UINT type = GetDriveTypeW(root.c_str());
            if (type == DRIVE_FIXED || type == DRIVE_REMOVABLE) {
                SearchGppInDir(root, 0, results);
                if (!results.empty()) return results[0];
            }
        }
    }
    return L"";
}

bool CompileAndRunBatch(const wstring& gppPath, const wstring& cppPath, int start, int end, HWND hWnd) {
    if (!FileExists(cppPath)) {
        wstring msg = L"找不到源文件:" + cppPath;
        MessageBoxW(hWnd, msg.c_str(), L"编译错误", MB_ICONERROR);
        return false;
    }
    wstring ext = cppPath.size() > 4 ? cppPath.substr(cppPath.size() - 4) : L"";
    if (ext != L".cpp" && ext != L".cxx" && ext != L".cc") {
        MessageBoxW(hWnd, L"请选择 C++ 源文件(.cpp/.cxx/.cc)", L"编译错误", MB_ICONERROR);
        return false;
    }

    if (g_outputDir.empty()) g_outputDir = GetDesktopPath();
    wstring tempExe = g_outputDir + L"\\temp_ac.exe";
    wstring cmdLine = L"\"" + gppPath + L"\" \"" + cppPath + L"\" -o \"" + tempExe + L"\"";

    HANDLE hRead, hWrite;
    SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
    if (!CreatePipe(&hRead, &hWrite, &sa, 0)) {
        MessageBoxW(hWnd, L"无法创建管道", L"错误", MB_ICONERROR);
        return false;
    }
    HANDLE hNull = CreateFileW(L"NUL", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if (hNull == INVALID_HANDLE_VALUE) {
        CloseHandle(hWrite);
        CloseHandle(hRead);
        MessageBoxW(hWnd, L"无法打开 NUL 设备", L"错误", MB_ICONERROR);
        return false;
    }

    STARTUPINFOW si = { sizeof(STARTUPINFOW) };
    si.dwFlags = STARTF_USESTDHANDLES;
    si.hStdOutput = hWrite;
    si.hStdError = hWrite;
    si.hStdInput = hNull;
    PROCESS_INFORMATION pi = { 0 };
    wchar_t* cmdBuf = new wchar_t[cmdLine.size() + 1];
    wcscpy(cmdBuf, cmdLine.c_str());
    BOOL success = CreateProcessW(NULL, cmdBuf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
    delete[] cmdBuf;
    CloseHandle(hWrite);
    CloseHandle(hNull);

    if (!success) {
        CloseHandle(hRead);
        DWORD err = GetLastError();
        wchar_t msg[512];
        swprintf(msg, 512, L"无法启动编译器,请检查 g++ 路径:\n%s\n错误代码:%lu", gppPath.c_str(), err);
        MessageBoxW(hWnd, msg, L"编译错误", MB_ICONERROR);
        return false;
    }
    wstring errOutput;
    char buffer[4096];
    DWORD bytesRead;
    while (ReadFile(hRead, buffer, sizeof(buffer) - 1, &bytesRead, NULL) && bytesRead > 0) {
        buffer[bytesRead] = '\0';
        errOutput += wstring(buffer, buffer + bytesRead);
    }
    CloseHandle(hRead);
    WaitForSingleObject(pi.hProcess, INFINITE);
    DWORD exitCode;
    GetExitCodeProcess(pi.hProcess, &exitCode);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    if (exitCode != 0) {
        if (errOutput.empty()) errOutput = L"(无错误输出,请检查源文件语法)";
        wchar_t errMsg[4096];
        swprintf(errMsg, 4096, L"编译失败,g++ 返回 %lu:\n%s", exitCode, errOutput.c_str());
        MessageBoxW(hWnd, errMsg, L"编译错误", MB_ICONERROR);
        return false;
    }

    for (int i = start; i <= end; ++i) {
        wchar_t inPath[MAX_PATH], outPath[MAX_PATH];
        swprintf(inPath, MAX_PATH, L"%s\\%d.in", g_outputDir.c_str(), i);
        swprintf(outPath, MAX_PATH, L"%s\\%d.out", g_outputDir.c_str(), i);
        wstring runCmd = L"cd /d \"" + g_outputDir + L"\" && \"" + tempExe + L"\" < \"" + inPath + L"\" > \"" + outPath + L"\"";
        _wsystem(runCmd.c_str());
    }

    DeleteFileW(tempExe.c_str());
    return true;
}

bool CompileAndRunSingle(const wstring& gppPath, const wstring& cppPath, const wstring& inPath, const wstring& outPath, HWND hWnd) {
    if (!FileExists(cppPath)) {
        wstring msg = L"找不到源文件:" + cppPath;
        MessageBoxW(hWnd, msg.c_str(), L"编译错误", MB_ICONERROR);
        return false;
    }
    wstring ext = cppPath.size() > 4 ? cppPath.substr(cppPath.size() - 4) : L"";
    if (ext != L".cpp" && ext != L".cxx" && ext != L".cc") {
        MessageBoxW(hWnd, L"请选择 C++ 源文件(.cpp/.cxx/.cc)", L"编译错误", MB_ICONERROR);
        return false;
    }

    wstring tempExe = g_outputDir + L"\\temp_single.exe";
    wstring cmdLine = L"\"" + gppPath + L"\" \"" + cppPath + L"\" -o \"" + tempExe + L"\"";

    HANDLE hRead, hWrite;
    SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
    if (!CreatePipe(&hRead, &hWrite, &sa, 0)) {
        MessageBoxW(hWnd, L"无法创建管道", L"错误", MB_ICONERROR);
        return false;
    }
    HANDLE hNull = CreateFileW(L"NUL", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
    if (hNull == INVALID_HANDLE_VALUE) {
        CloseHandle(hWrite);
        CloseHandle(hRead);
        MessageBoxW(hWnd, L"无法打开 NUL 设备", L"错误", MB_ICONERROR);
        return false;
    }

    STARTUPINFOW si = { sizeof(STARTUPINFOW) };
    si.dwFlags = STARTF_USESTDHANDLES;
    si.hStdOutput = hWrite;
    si.hStdError = hWrite;
    si.hStdInput = hNull;
    PROCESS_INFORMATION pi = { 0 };
    wchar_t* cmdBuf = new wchar_t[cmdLine.size() + 1];
    wcscpy(cmdBuf, cmdLine.c_str());
    BOOL success = CreateProcessW(NULL, cmdBuf, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi);
    delete[] cmdBuf;
    CloseHandle(hWrite);
    CloseHandle(hNull);

    if (!success) {
        CloseHandle(hRead);
        DWORD err = GetLastError();
        wchar_t msg[512];
        swprintf(msg, 512, L"无法启动编译器,请检查 g++ 路径:\n%s\n错误代码:%lu", gppPath.c_str(), err);
        MessageBoxW(hWnd, msg, L"编译错误", MB_ICONERROR);
        return false;
    }
    wstring errOutput;
    char buffer[4096];
    DWORD bytesRead;
    while (ReadFile(hRead, buffer, sizeof(buffer) - 1, &bytesRead, NULL) && bytesRead > 0) {
        buffer[bytesRead] = '\0';
        errOutput += wstring(buffer, buffer + bytesRead);
    }
    CloseHandle(hRead);
    WaitForSingleObject(pi.hProcess, INFINITE);
    DWORD exitCode;
    GetExitCodeProcess(pi.hProcess, &exitCode);
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hThread);
    if (exitCode != 0) {
        if (errOutput.empty()) errOutput = L"(无错误输出,请检查源文件语法)";
        wchar_t errMsg[4096];
        swprintf(errMsg, 4096, L"编译失败,g++ 返回 %lu:\n%s", exitCode, errOutput.c_str());
        MessageBoxW(hWnd, errMsg, L"编译错误", MB_ICONERROR);
        return false;
    }

    wstring runCmd = L"cd /d \"" + g_outputDir + L"\" && \"" + tempExe + L"\" < \"" + inPath + L"\" > \"" + outPath + L"\"";
    _wsystem(runCmd.c_str());

    DeleteFileW(tempExe.c_str());
    return true;
}

// 颜色持久化
void SaveColorSettings() {
    HKEY hKey;
    if (RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\TestDataGenerator", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {
        RegSetValueExW(hKey, L"TextColor", 0, REG_DWORD, (BYTE*)&g_textColor, sizeof(COLORREF));
        RegSetValueExW(hKey, L"BgColor", 0, REG_DWORD, (BYTE*)&g_bgColor, sizeof(COLORREF));
        RegCloseKey(hKey);
    }
}
void LoadColorSettings() {
    HKEY hKey;
    if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\TestDataGenerator", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
        DWORD size = sizeof(COLORREF);
        RegQueryValueExW(hKey, L"TextColor", NULL, NULL, (BYTE*)&g_textColor, &size);
        RegQueryValueExW(hKey, L"BgColor", NULL, NULL, (BYTE*)&g_bgColor, &size);
        RegCloseKey(hKey);
    }
}
void ApplyColorSettings(HWND hWnd) { InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); }
void SetDefaultColors(HWND hWnd) {
    g_textColor = RGB(0, 0, 0);
    g_bgColor = RGB(255, 255, 255);
    SaveColorSettings();
    ApplyColorSettings(hWnd);
    SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"已恢复默认颜色(黑字白底)");
}
void ShowColorDialog(HWND hWnd) {
    COLORREF customColors[16] = { 0 };
    CHOOSECOLOR cc = { sizeof(CHOOSECOLOR) };
    cc.hwndOwner = hWnd;
    cc.rgbResult = g_textColor;
    cc.lpCustColors = customColors;
    cc.Flags = CC_RGBINIT | CC_FULLOPEN;
    if (ChooseColor(&cc)) g_textColor = cc.rgbResult; else return;
    cc.rgbResult = g_bgColor;
    if (ChooseColor(&cc)) g_bgColor = cc.rgbResult; else return;
    SaveColorSettings();
    ApplyColorSettings(hWnd);
    SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"颜色已更改");
}

void SwitchMode(HWND hWnd, int mode) {
    g_currentMode = mode;
    int randomCtrls[] = { IDC_EDIT_START, IDC_EDIT_END, IDC_COMBO_TYPE, IDC_EDIT_RANGE1, IDC_EDIT_RANGE2, IDC_EDIT_STRLEN,
        IDC_EDIT_COUNT, IDC_CHECK_WRITE, IDC_EDIT_VAR_TEXT, IDC_BUTTON_GEN,
        IDC_STATIC_START_LABEL, IDC_STATIC_END_LABEL, IDC_STATIC_TYPE_LABEL,
        IDC_STATIC_RANGE_LABEL, IDC_STATIC_RANGESEP, IDC_STATIC_COUNT_LABEL, IDC_STATIC_VAR_LABEL };
    int manualCtrls[] = { IDC_EDIT_MANUAL_INNAME, IDC_EDIT_MANUAL_INCONTENT, IDC_BUTTON_MANUAL_SAVEIN,
        IDC_STATIC_MANUAL_LABEL1, IDC_STATIC_MANUAL_LABEL2 };
    if (mode == 0) {
        for (int i = 0; i < sizeof(randomCtrls) / sizeof(randomCtrls[0]); ++i) ShowWindow(GetDlgItem(hWnd, randomCtrls[i]), SW_SHOW);
        for (int i = 0; i < sizeof(manualCtrls) / sizeof(manualCtrls[0]); ++i) ShowWindow(GetDlgItem(hWnd, manualCtrls[i]), SW_HIDE);
    }
    else {
        for (int i = 0; i < sizeof(randomCtrls) / sizeof(randomCtrls[0]); ++i) ShowWindow(GetDlgItem(hWnd, randomCtrls[i]), SW_HIDE);
        for (int i = 0; i < sizeof(manualCtrls) / sizeof(manualCtrls[0]); ++i) ShowWindow(GetDlgItem(hWnd, manualCtrls[i]), SW_SHOW);
    }
    InvalidateRect(hWnd, NULL, TRUE);
    UpdateWindow(hWnd);
}

void ResizeControls(HWND hWnd, int cx, int cy) {
    int dx = cx - g_baseClientWidth;
    int dy = cy - g_baseClientHeight;

    // 输出目录行
    HWND hOutDirEdit = GetDlgItem(hWnd, IDC_EDIT_OUTDIR);
    HWND hOutDirBtn = GetDlgItem(hWnd, IDC_BUTTON_OUTDIR_BROWSE);
    if (hOutDirEdit && hOutDirBtn) {
        int outY = 400 + dy;
        int newOutW = 550 + dx;
        SetWindowPos(hOutDirEdit, NULL, 110, outY, newOutW, 25, SWP_NOZORDER);
        SetWindowPos(hOutDirBtn, NULL, 110 + newOutW + 10, outY, 70, 25, SWP_NOZORDER);
    }

    if (g_currentMode == 0) {
        HWND hVarEdit = GetDlgItem(hWnd, IDC_EDIT_VAR_TEXT);
        if (hVarEdit) SetWindowPos(hVarEdit, NULL, 20, 220, 600 + dx, (140 > (110 + dy) ? 140 : (110 + dy)), SWP_NOZORDER);
        HWND hGenBtn = GetDlgItem(hWnd, IDC_BUTTON_GEN);
        if (hGenBtn) SetWindowPos(hGenBtn, NULL, 20, 440, 120, 35, SWP_NOZORDER);
    }
    else {
        HWND hInName = GetDlgItem(hWnd, IDC_EDIT_MANUAL_INNAME);
        HWND hInContent = GetDlgItem(hWnd, IDC_EDIT_MANUAL_INCONTENT);
        HWND hBtnSaveIn = GetDlgItem(hWnd, IDC_BUTTON_MANUAL_SAVEIN);
        if (hInName) SetWindowPos(hInName, NULL, 110, 60, 450 + dx, 25, SWP_NOZORDER);
        if (hInContent) SetWindowPos(hInContent, NULL, 110, 100, 600 + dx, (140 > (110 + dy) ? 140 : (110 + dy)), SWP_NOZORDER);
        if (hBtnSaveIn) SetWindowPos(hBtnSaveIn, NULL, 20, 260, 120, 35, SWP_NOZORDER);
    }

    HWND hAuthor = GetDlgItem(hWnd, IDC_STATIC_AUTHOR);
    if (hAuthor) SetWindowPos(hAuthor, NULL, 20, 370, 850 + dx, 20, SWP_NOZORDER);

    // C++ 源文件选择
    HWND hEditPath = GetDlgItem(hWnd, IDC_EDIT_CPP_PATH);
    HWND hBtnBrowse = GetDlgItem(hWnd, IDC_BUTTON_BROWSE);
    if (hEditPath && hBtnBrowse) {
        int pathY = 490 + dy;
        int newPathW = 500 + dx;
        SetWindowPos(hEditPath, NULL, 20, pathY, newPathW, 25, SWP_NOZORDER);
        SetWindowPos(hBtnBrowse, NULL, 20 + newPathW + 10, pathY, 70, 25, SWP_NOZORDER);
    }

    // 三个功能按钮
    HWND hCompile = GetDlgItem(hWnd, IDC_BUTTON_UNIFIED_COMPILE);
    HWND hColorBtn = GetDlgItem(hWnd, IDC_BUTTON_COLOR_SETTING);
    HWND hDefaultBtn = GetDlgItem(hWnd, IDC_BUTTON_DEFAULT_COLOR);
    if (hCompile && hColorBtn && hDefaultBtn) {
        int btnY = 540 + dy;
        SetWindowPos(hCompile, NULL, 20, btnY, 150, 35, SWP_NOZORDER);
        SetWindowPos(hColorBtn, NULL, 190, btnY, 100, 35, SWP_NOZORDER);
        SetWindowPos(hDefaultBtn, NULL, 310, btnY, 120, 35, SWP_NOZORDER);
    }

    // g++ 路径
    HWND hGppEdit = GetDlgItem(hWnd, IDC_EDIT_GPP_PATH);
    HWND hGppBrowse = GetDlgItem(hWnd, IDC_BUTTON_GPP_BROWSE);
    HWND hGppAuto = GetDlgItem(hWnd, IDC_BUTTON_GPP_AUTO);
    if (hGppEdit && hGppBrowse && hGppAuto) {
        int gppY = 590 + dy;
        int newGppW = 400 + dx;
        SetWindowPos(hGppEdit, NULL, 125, gppY, newGppW, 25, SWP_NOZORDER);
        int newBrowseX = 125 + newGppW + 5;
        SetWindowPos(hGppBrowse, NULL, newBrowseX, gppY, 60, 25, SWP_NOZORDER);
        SetWindowPos(hGppAuto, NULL, newBrowseX + 65, gppY, 70, 25, SWP_NOZORDER);
    }

    HWND hStatus = GetDlgItem(hWnd, IDC_STATIC_STATUS);
    if (hStatus) SetWindowPos(hStatus, NULL, 20, 635 + dy, 600 + dx, 25, SWP_NOZORDER);
}

LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    switch (msg) {
    case WM_CREATE: {
        g_hFontNormal = CreateFontW(-16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
            DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
            CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI");
        g_hFontBold = CreateFontW(-16, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE,
            DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
            CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Segoe UI");

        // 模式单选
        CreateWindowW(L"BUTTON", L"随机生成", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON | WS_GROUP,
            20, 2, 90, 20, hWnd, (HMENU)IDC_RADIO_MODE_RANDOM, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"自编译", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
            120, 2, 90, 20, hWnd, (HMENU)IDC_RADIO_MODE_MANUAL, g_hInst, NULL);
        SendMessage(GetDlgItem(hWnd, IDC_RADIO_MODE_RANDOM), BM_SETCHECK, BST_CHECKED, 0);

        // 起始/结束 ID
        CreateWindowW(L"STATIC", L"起始 ID:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 30, 90, 25, hWnd, (HMENU)IDC_STATIC_START_LABEL, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER, 120, 30, 100, 25, hWnd, (HMENU)IDC_EDIT_START, g_hInst, NULL);
        CreateWindowW(L"STATIC", L"结束 ID:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 250, 30, 90, 25, hWnd, (HMENU)IDC_STATIC_END_LABEL, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER, 350, 30, 100, 25, hWnd, (HMENU)IDC_EDIT_END, g_hInst, NULL);

        // 数据类型
        CreateWindowW(L"STATIC", L"数据类型:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 70, 90, 25, hWnd, (HMENU)IDC_STATIC_TYPE_LABEL, g_hInst, NULL);
        HWND hCombo = CreateWindowW(L"COMBOBOX", L"", WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER, 120, 70, 180, 150, hWnd, (HMENU)IDC_COMBO_TYPE, g_hInst, NULL);
        SendMessageW(hCombo, CB_ADDSTRING, 0, (LPARAM)L"整数(随机)");
        SendMessageW(hCombo, CB_ADDSTRING, 0, (LPARAM)L"整数(不重复)");
        SendMessageW(hCombo, CB_ADDSTRING, 0, (LPARAM)L"字符串(小写)");
        SendMessageW(hCombo, CB_ADDSTRING, 0, (LPARAM)L"字符串(大写)");
        SendMessageW(hCombo, CB_ADDSTRING, 0, (LPARAM)L"字符串(混合)");
        SendMessage(hCombo, CB_SETCURSEL, 0, 0);

        // 范围/长度
        CreateWindowW(L"STATIC", L"范围/长度:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 110, 90, 25, hWnd, (HMENU)IDC_STATIC_RANGE_LABEL, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 120, 110, 80, 25, hWnd, (HMENU)IDC_EDIT_RANGE1, g_hInst, NULL);
        CreateWindowW(L"STATIC", L"~", WS_CHILD | WS_VISIBLE | SS_CENTER, 205, 110, 20, 25, hWnd, (HMENU)IDC_STATIC_RANGESEP, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 230, 110, 80, 25, hWnd, (HMENU)IDC_EDIT_RANGE2, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 120, 110, 190, 25, hWnd, (HMENU)IDC_EDIT_STRLEN, g_hInst, NULL);
        ShowWindow(GetDlgItem(hWnd, IDC_EDIT_STRLEN), SW_HIDE);

        // 每文件个数
        CreateWindowW(L"STATIC", L"每文件个数:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 150, 90, 25, hWnd, (HMENU)IDC_STATIC_COUNT_LABEL, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_NUMBER, 120, 150, 100, 25, hWnd, (HMENU)IDC_EDIT_COUNT, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"在文件中写入个数", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 240, 150, 150, 25, hWnd, (HMENU)IDC_CHECK_WRITE, g_hInst, NULL);

        // 额外变量
        CreateWindowW(L"STATIC", L"额外变量(每行 name=value 或 name value):", WS_CHILD | WS_VISIBLE | SS_LEFT, 20, 190, 400, 25, hWnd, (HMENU)IDC_STATIC_VAR_LABEL, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,
            20, 215, 600, 140, hWnd, (HMENU)IDC_EDIT_VAR_TEXT, g_hInst, NULL);

        // 作者信息
        CreateWindowW(L"STATIC",
            L"作者:starryfast | Bilibili 同名 | Luogu 2070675 | 源码:https://github.com/starryfast/Code-date-creation",
            WS_CHILD | WS_VISIBLE | SS_LEFT, 20, 370, 860, 20, hWnd, (HMENU)IDC_STATIC_AUTHOR, g_hInst, NULL);

        // 生成位置
        CreateWindowW(L"STATIC", L"生成位置:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 400, 90, 25, hWnd, (HMENU)IDC_STATIC_OUTDIR_LABEL, g_hInst, NULL);
        g_outputDir = GetDesktopPath();
        CreateWindowW(L"EDIT", g_outputDir.c_str(), WS_CHILD | WS_VISIBLE | WS_BORDER | ES_READONLY, 120, 400, 550, 25, hWnd, (HMENU)IDC_EDIT_OUTDIR, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"浏览...", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 680, 400, 70, 25, hWnd, (HMENU)IDC_BUTTON_OUTDIR_BROWSE, g_hInst, NULL);

        // 生成 .in 按钮
        CreateWindowW(L"BUTTON", L"生成 .in 文件", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 20, 440, 120, 35, hWnd, (HMENU)IDC_BUTTON_GEN, g_hInst, NULL);

        // C++ 源文件选择
        CreateWindowW(L"BUTTON", L"浏览...", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 580, 490, 70, 25, hWnd, (HMENU)IDC_BUTTON_BROWSE, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 20, 490, 550, 25, hWnd, (HMENU)IDC_EDIT_CPP_PATH, g_hInst, NULL);

        // 三个功能按钮(生成.out、颜色设置、默认颜色)
        CreateWindowW(L"BUTTON", L"生成 .out", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 20, 540, 150, 35, hWnd, (HMENU)IDC_BUTTON_UNIFIED_COMPILE, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"颜色设置", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 190, 540, 100, 35, hWnd, (HMENU)IDC_BUTTON_COLOR_SETTING, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"设为默认颜色", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 310, 540, 120, 35, hWnd, (HMENU)IDC_BUTTON_DEFAULT_COLOR, g_hInst, NULL);

        // g++ 路径
        CreateWindowW(L"STATIC", L"g++ 编译器路径:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 590, 100, 25, hWnd, NULL, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 125, 590, 400, 25, hWnd, (HMENU)IDC_EDIT_GPP_PATH, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"浏览...", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 530, 590, 60, 25, hWnd, (HMENU)IDC_BUTTON_GPP_BROWSE, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"自动检测", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 595, 590, 70, 25, hWnd, (HMENU)IDC_BUTTON_GPP_AUTO, g_hInst, NULL);

        // 状态栏
        CreateWindowW(L"STATIC", L"就绪", WS_CHILD | WS_VISIBLE | SS_SUNKEN, 20, 635, 600, 25, hWnd, (HMENU)IDC_STATIC_STATUS, g_hInst, NULL);

        // 自编译模式控件(初始隐藏)
        CreateWindowW(L"STATIC", L"输入文件名:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 60, 90, 25, hWnd, (HMENU)IDC_STATIC_MANUAL_LABEL1, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER, 120, 60, 450, 25, hWnd, (HMENU)IDC_EDIT_MANUAL_INNAME, g_hInst, NULL);
        CreateWindowW(L"STATIC", L"输入内容:", WS_CHILD | WS_VISIBLE | SS_RIGHT, 20, 100, 90, 25, hWnd, (HMENU)IDC_STATIC_MANUAL_LABEL2, g_hInst, NULL);
        CreateWindowW(L"EDIT", L"", WS_CHILD | WS_VISIBLE | WS_BORDER | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,
            120, 100, 600, 140, hWnd, (HMENU)IDC_EDIT_MANUAL_INCONTENT, g_hInst, NULL);
        CreateWindowW(L"BUTTON", L"保存为 .in", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 20, 260, 120, 35, hWnd, (HMENU)IDC_BUTTON_MANUAL_SAVEIN, g_hInst, NULL);

        int hideIds[] = { IDC_EDIT_MANUAL_INNAME, IDC_EDIT_MANUAL_INCONTENT, IDC_BUTTON_MANUAL_SAVEIN,
            IDC_STATIC_MANUAL_LABEL1, IDC_STATIC_MANUAL_LABEL2 };
        for (int i = 0; i < sizeof(hideIds) / sizeof(hideIds[0]); ++i)
            ShowWindow(GetDlgItem(hWnd, hideIds[i]), SW_HIDE);

        // 设置字体
        HWND hChild = GetWindow(hWnd, GW_CHILD);
        while (hChild) {
            SendMessage(hChild, WM_SETFONT, (WPARAM)g_hFontNormal, TRUE);
            hChild = GetNextWindow(hChild, GW_HWNDNEXT);
        }

        LoadColorSettings();
        ApplyColorSettings(hWnd);

        SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"正在搜索 g++,请稍候...");
        wstring gppPath = AutoFindGpp();
        if (!gppPath.empty()) {
            SetDlgItemTextW(hWnd, IDC_EDIT_GPP_PATH, gppPath.c_str());
            SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"已找到 g++,准备就绪。");
        }
        else {
            SetDlgItemTextW(hWnd, IDC_EDIT_GPP_PATH, L"未找到,请手动指定。");
            SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"请手动选择 g++.exe");
        }

        RECT rcClient;
        GetClientRect(hWnd, &rcClient);
        g_baseClientWidth = rcClient.right;
        g_baseClientHeight = rcClient.bottom;
        SwitchMode(hWnd, 0);
        break;
    }
    case WM_COMMAND: {
        int id = LOWORD(wParam);
        if (id == IDC_RADIO_MODE_RANDOM) SwitchMode(hWnd, 0);
        else if (id == IDC_RADIO_MODE_MANUAL) SwitchMode(hWnd, 1);
        else if (id == IDC_COMBO_TYPE && HIWORD(wParam) == CBN_SELCHANGE) {
            int sel = SendMessage(GetDlgItem(hWnd, IDC_COMBO_TYPE), CB_GETCURSEL, 0, 0);
            BOOL showRange = (sel == 0 || sel == 1);
            BOOL showStrLen = (sel >= 2);
            ShowWindow(GetDlgItem(hWnd, IDC_EDIT_RANGE1), showRange ? SW_SHOW : SW_HIDE);
            ShowWindow(GetDlgItem(hWnd, IDC_EDIT_RANGE2), showRange ? SW_SHOW : SW_HIDE);
            ShowWindow(GetDlgItem(hWnd, IDC_EDIT_STRLEN), showStrLen ? SW_SHOW : SW_HIDE);
            ShowWindow(GetDlgItem(hWnd, IDC_STATIC_RANGESEP), showRange ? SW_SHOW : SW_HIDE);
        }
        else if (id == IDC_BUTTON_COLOR_SETTING) ShowColorDialog(hWnd);
        else if (id == IDC_BUTTON_DEFAULT_COLOR) SetDefaultColors(hWnd);
        else if (id == IDC_BUTTON_OUTDIR_BROWSE) {
            BROWSEINFOW bi = { 0 };
            bi.hwndOwner = hWnd;
            bi.lpszTitle = L"选择生成 .in / .out 文件的文件夹";
            bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
            LPITEMIDLIST pidl = SHBrowseForFolderW(&bi);
            if (pidl) {
                wchar_t path[MAX_PATH];
                if (SHGetPathFromIDListW(pidl, path)) {
                    g_outputDir = path;
                    SetDlgItemTextW(hWnd, IDC_EDIT_OUTDIR, g_outputDir.c_str());
                }
                ILFree(pidl);
            }
        }
        else if (id == IDC_BUTTON_GEN) {
            int start = GetDlgItemInt(hWnd, IDC_EDIT_START, NULL, FALSE);
            int end = GetDlgItemInt(hWnd, IDC_EDIT_END, NULL, FALSE);
            int modeIdx = SendMessage(GetDlgItem(hWnd, IDC_COMBO_TYPE), CB_GETCURSEL, 0, 0);
            int dataType = modeIdx + 1;
            long long range1 = 0, range2 = 0; int strLen = 0;
            if (dataType <= 2) {
                range1 = GetDlgItemInt(hWnd, IDC_EDIT_RANGE1, NULL, TRUE);
                range2 = GetDlgItemInt(hWnd, IDC_EDIT_RANGE2, NULL, TRUE);
            }
            else {
                strLen = GetDlgItemInt(hWnd, IDC_EDIT_STRLEN, NULL, FALSE);
            }
            int countPerFile = GetDlgItemInt(hWnd, IDC_EDIT_COUNT, NULL, FALSE);
            bool writeCount = (SendMessage(GetDlgItem(hWnd, IDC_CHECK_WRITE), BM_GETCHECK, 0, 0) == BST_CHECKED);

            if (start > end) { MessageBoxW(hWnd, L"起始 ID 不能大于结束 ID。", L"错误", MB_ICONERROR); break; }
            if (countPerFile <= 0) { MessageBoxW(hWnd, L"每文件个数必须大于 0。", L"错误", MB_ICONERROR); break; }
            if (dataType == 2) {
                unsigned long long rangeSize = (range2 >= range1) ? (unsigned long long)(range2 - range1 + 1) : 0;
                if ((unsigned long long)countPerFile > rangeSize) {
                    MessageBoxW(hWnd, L"范围内没有足够的不重复数字。", L"错误", MB_ICONERROR);
                    break;
                }
            }
            if (dataType >= 3 && strLen <= 0) {
                MessageBoxW(hWnd, L"字符串长度必须大于 0。", L"错误", MB_ICONERROR);
                break;
            }

            vector<ExtraVar> vars = ParseExtraVars(GetDlgItem(hWnd, IDC_EDIT_VAR_TEXT));
            SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"正在生成 .in 文件...");
            if (GenerateInputFiles(start, end, dataType, range1, range2, strLen, countPerFile, writeCount, vars)) {
                SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"所有 .in 文件已生成到指定位置!");
                MessageBoxW(hWnd, L"生成完毕!", L"成功", MB_OK);
            }
            else {
                SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"生成失败,请检查权限或路径。");
            }
        }
        else if (id == IDC_BUTTON_MANUAL_SAVEIN) {
            wchar_t inName[MAX_PATH] = { 0 };
            GetDlgItemTextW(hWnd, IDC_EDIT_MANUAL_INNAME, inName, MAX_PATH);
            if (wcslen(inName) == 0) {
                MessageBoxW(hWnd, L"请输入 .in 文件名。", L"提示", MB_ICONINFORMATION);
                break;
            }
            wstring nameStr = inName;
            // 自动添加 .in 后缀
            if (nameStr.find(L'.') == wstring::npos) {
                nameStr += L".in";
            }
            wstring fullInPath = (nameStr.find(L'\\') == wstring::npos) ? (g_outputDir + L"\\" + nameStr) : nameStr;
            int len = GetWindowTextLengthW(GetDlgItem(hWnd, IDC_EDIT_MANUAL_INCONTENT));
            wchar_t* contentBuf = new wchar_t[len + 1];
            GetDlgItemTextW(hWnd, IDC_EDIT_MANUAL_INCONTENT, contentBuf, len + 1);
            FILE* fp = _wfopen(fullInPath.c_str(), L"w");
            if (!fp) {
                delete[] contentBuf;
                MessageBoxW(hWnd, L"无法创建输入文件,请检查路径和权限。", L"错误", MB_ICONERROR);
                break;
            }
            fwprintf(fp, L"%s", contentBuf);
            fclose(fp);
            delete[] contentBuf;
            SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"输入文件已保存。");
            MessageBoxW(hWnd, L".in 文件保存完毕!", L"成功", MB_OK);
        }
        else if (id == IDC_BUTTON_BROWSE) {
            OPENFILENAMEW ofn = { 0 };
            wchar_t file[MAX_PATH] = { 0 };
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = hWnd;
            ofn.lpstrFilter = L"C++ 源文件\0*.cpp\0所有文件\0*.*\0";
            ofn.lpstrFile = file;
            ofn.nMaxFile = MAX_PATH;
            ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
            if (GetOpenFileNameW(&ofn)) SetDlgItemTextW(hWnd, IDC_EDIT_CPP_PATH, file);
        }
        else if (id == IDC_BUTTON_GPP_BROWSE) {
            OPENFILENAMEW ofn = { 0 };
            wchar_t file[MAX_PATH] = { 0 };
            ofn.lStructSize = sizeof(ofn);
            ofn.hwndOwner = hWnd;
            ofn.lpstrFilter = L"可执行文件\0*.exe\0所有文件\0*.*\0";
            ofn.lpstrFile = file;
            ofn.nMaxFile = MAX_PATH;
            ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
            if (GetOpenFileNameW(&ofn)) SetDlgItemTextW(hWnd, IDC_EDIT_GPP_PATH, file);
        }
        else if (id == IDC_BUTTON_GPP_AUTO) {
            SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"正在全盘搜索 g++,请稍候...");
            wstring gppPath = AutoFindGpp();
            if (!gppPath.empty()) {
                SetDlgItemTextW(hWnd, IDC_EDIT_GPP_PATH, gppPath.c_str());
                SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"已自动找到 g++。");
            }
            else {
                SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"未找到 g++,请手动选择。");
                MessageBoxW(hWnd, L"找不到 g++,请点击"浏览..."选择您的 g++.exe。", L"提示", MB_ICONINFORMATION);
            }
        }
        else if (id == IDC_BUTTON_UNIFIED_COMPILE) {
            wchar_t cppPath[MAX_PATH];
            GetDlgItemTextW(hWnd, IDC_EDIT_CPP_PATH, cppPath, MAX_PATH);
            if (!cppPath[0]) { MessageBoxW(hWnd, L"请先选择一个 C++ 源文件。", L"提示", MB_ICONINFORMATION); break; }
            wchar_t gppPath[MAX_PATH];
            GetDlgItemTextW(hWnd, IDC_EDIT_GPP_PATH, gppPath, MAX_PATH);
            if (!gppPath[0] || !FileExists(gppPath)) {
                MessageBoxW(hWnd, L"请设置有效的 g++ 编译器路径。", L"错误", MB_ICONERROR); break;
            }

            if (g_currentMode == 0) {
                int start = GetDlgItemInt(hWnd, IDC_EDIT_START, NULL, FALSE);
                int end = GetDlgItemInt(hWnd, IDC_EDIT_END, NULL, FALSE);
                if (start > end) { MessageBoxW(hWnd, L"起始 ID 不能大于结束 ID。", L"错误", MB_ICONERROR); break; }
                SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"正在编译并运行,请稍候...");
                if (CompileAndRunBatch(gppPath, cppPath, start, end, hWnd)) {
                    SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"所有 .out 文件已生成到指定位置!");
                    MessageBoxW(hWnd, L"评测完成!", L"成功", MB_OK);
                }
                else {
                    SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"编译或运行失败。");
                }
            }
            else {
                wchar_t inName[MAX_PATH] = { 0 };
                GetDlgItemTextW(hWnd, IDC_EDIT_MANUAL_INNAME, inName, MAX_PATH);
                if (wcslen(inName) == 0) {
                    MessageBoxW(hWnd, L"请先填写输入文件名并保存 .in 文件。", L"提示", MB_ICONINFORMATION);
                    break;
                }
                wstring nameStr = inName;
                if (nameStr.find(L'.') == wstring::npos) {
                    nameStr += L".in";
                }
                wstring fullInPath = (nameStr.find(L'\\') == wstring::npos) ? (g_outputDir + L"\\" + nameStr) : nameStr;
                if (!FileExists(fullInPath)) {
                    MessageBoxW(hWnd, L"指定的 .in 文件不存在,请先点击"保存为 .in"。", L"错误", MB_ICONERROR);
                    break;
                }
                wstring fullOutPath = fullInPath;
                size_t dot = fullOutPath.find_last_of(L'.');
                if (dot != wstring::npos) fullOutPath = fullOutPath.substr(0, dot);
                fullOutPath += L".out";

                SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"正在编译并运行,请稍候...");
                if (CompileAndRunSingle(gppPath, cppPath, fullInPath, fullOutPath, hWnd)) {
                    SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L".out 文件已生成到指定位置!");
                    MessageBoxW(hWnd, L"生成完毕!", L"成功", MB_OK);
                }
                else {
                    SetDlgItemTextW(hWnd, IDC_STATIC_STATUS, L"编译或运行失败。");
                }
            }
        }
        break;
    }
    case WM_SIZE: { ResizeControls(hWnd, LOWORD(lParam), HIWORD(lParam)); return 0; }
    case WM_GETMINMAXINFO: {
        MINMAXINFO* mmi = (MINMAXINFO*)lParam;
        mmi->ptMinTrackSize.x = 950;
        mmi->ptMinTrackSize.y = 740;
        return 0;
    }
    case WM_CTLCOLORSTATIC: {
        HDC hdc = (HDC)wParam; HWND hStatic = (HWND)lParam;
        int ctrlId = GetDlgCtrlID(hStatic);
        if (ctrlId == IDC_STATIC_AUTHOR) {
            SetTextColor(hdc, RGB(80, 80, 80)); SetBkColor(hdc, g_bgColor);
            static HBRUSH hBrushAuthor = NULL;
            if (hBrushAuthor) DeleteObject(hBrushAuthor);
            hBrushAuthor = CreateSolidBrush(g_bgColor);
            return (LRESULT)hBrushAuthor;
        }
        SetTextColor(hdc, g_textColor); SetBkColor(hdc, g_bgColor);
        static HBRUSH hBrushStatic = NULL;
        if (hBrushStatic) DeleteObject(hBrushStatic);
        hBrushStatic = CreateSolidBrush(g_bgColor);
        return (LRESULT)hBrushStatic;
    }
    case WM_CTLCOLOREDIT:
    case WM_CTLCOLORLISTBOX: {
        HDC hdc = (HDC)wParam;
        SetTextColor(hdc, g_textColor); SetBkColor(hdc, g_bgColor);
        static HBRUSH hBrushEdit = NULL;
        if (hBrushEdit) DeleteObject(hBrushEdit);
        hBrushEdit = CreateSolidBrush(g_bgColor);
        return (LRESULT)hBrushEdit;
    }
    case WM_CTLCOLORBTN: {
        HDC hdc = (HDC)wParam; HWND hBtn = (HWND)lParam;
        LONG_PTR style = GetWindowLongPtr(hBtn, GWL_STYLE);
        if (style & BS_AUTOCHECKBOX) {
            SetTextColor(hdc, g_textColor); SetBkColor(hdc, g_bgColor);
            static HBRUSH hBrushChk = NULL;
            if (hBrushChk) DeleteObject(hBrushChk);
            hBrushChk = CreateSolidBrush(g_bgColor);
            return (LRESULT)hBrushChk;
        }
        else {
            SetTextColor(hdc, RGB(255, 255, 255)); SetBkColor(hdc, RGB(0, 120, 212));
            static HBRUSH hBrushBtn = CreateSolidBrush(RGB(0, 120, 212));
            return (LRESULT)hBrushBtn;
        }
    }
    case WM_ERASEBKGND: {
        RECT rc; GetClientRect(hWnd, &rc);
        HBRUSH hBrush = CreateSolidBrush(g_bgColor);
        FillRect((HDC)wParam, &rc, hBrush);
        DeleteObject(hBrush);
        return TRUE;
    }
    case WM_DESTROY:
        DeleteObject(g_hFontNormal); DeleteObject(g_hFontBold);
        PostQuitMessage(0);
        break;
    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
    HMODULE hUser32 = GetModuleHandleW(L"user32.dll");
    if (hUser32) {
        typedef BOOL(WINAPI* SetProcessDPIAware_t)(void);
        SetProcessDPIAware_t pSetProcessDPIAware = (SetProcessDPIAware_t)GetProcAddress(hUser32, "SetProcessDPIAware");
        if (pSetProcessDPIAware) pSetProcessDPIAware();
    }

    srand((unsigned)time(NULL));
    g_hInst = hInstance;
    WNDCLASSEXW wc = { 0 };
    wc.cbSize = sizeof(WNDCLASSEXW);
    wc.lpfnWndProc = WndProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.lpszClassName = L"CDCDataGenerator";
    RegisterClassExW(&wc);
    g_hMainWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"CDCDataGenerator", L"测试数据生成器 5.0.0",
        WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 1000, 780, NULL, NULL, hInstance, NULL);
    if (!g_hMainWnd) return 1;
    ShowWindow(g_hMainWnd, nCmdShow);
    UpdateWindow(g_hMainWnd);
    MSG msg;
    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
    return msg.wParam;
}

祝愿

祝大家高考顺利学业有成,再见!