Files
jiu/client/windows/runner/main.cpp
T
wangjia 056ae914ce
Deploy / build-linux-web (push) Successful in 52s
Deploy / build-windows (push) Successful in 1m38s
Deploy / build-macos (push) Successful in 1m3s
Deploy / release-deploy (push) Successful in 1m25s
fix(client): Windows main.cpp 用 ASCII 十六进制转义写标题,修复 C4819
v1.0.14 Windows 构建失败:main.cpp 含中文(u8 标题+中文注释),MSVC 在
GBK(936) 代码页报 C4819「字符无法表示」,而 runner 开了 /WX 警告即错误。
改为标题用 UTF-8 字节的 \x 十六进制转义、注释改英文,源码纯 ASCII,
运行时 MultiByteToWideChar(CP_UTF8) 解码,窗口标题仍是岩美酒库。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 08:32:48 +08:00

58 lines
1.9 KiB
C++

#include <flutter/dart_project.h>
#include <flutter/flutter_view_controller.h>
#include <windows.h>
#include <string>
#include "flutter_window.h"
#include "utils.h"
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
// Attach to console when present (e.g., 'flutter run') or create a
// new console when running with a debugger.
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
CreateAndAttachConsole();
}
// Initialize COM, so that it is available for use in the library and/or
// plugins.
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
flutter::DartProject project(L"data");
std::vector<std::string> command_line_arguments =
GetCommandLineArguments();
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
FlutterWindow window(project);
Win32Window::Point origin(10, 10);
Win32Window::Size size(1280, 720);
// Window title as UTF-8 bytes (hex-escaped to keep this source pure ASCII and
// avoid MSVC C4819 under GBK code page 936). Decoded to UTF-16 for Win32.
// Bytes below are the UTF-8 encoding of the Chinese app title.
const std::string title_utf8 =
"\xE5\xB2\xA9\xE7\xBE\x8E\xE9\x85\x92\xE5\xBA\x93";
int title_len = ::MultiByteToWideChar(CP_UTF8, 0, title_utf8.c_str(), -1,
nullptr, 0);
std::wstring window_title(title_len > 0 ? title_len - 1 : 0, L'\0');
if (title_len > 0) {
::MultiByteToWideChar(CP_UTF8, 0, title_utf8.c_str(), -1, &window_title[0],
title_len);
}
if (!window.Create(window_title, origin, size)) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::CoUninitialize();
return EXIT_SUCCESS;
}