Files
astral/windows/runner/main.cpp
T
会做饭的二哈 38acea1bf5 feat: 添加窗口标题并优化Windows应用配置
- 在`windowconfiguration.dart`中添加窗口标题"Astral"并确保窗口管理器初始化
- 在`runner.exe.manifest`中添加UTF-8编码、长路径支持和SegmentHeap堆类型配置
- 在`Runner.rc`中更新应用描述、内部名称、原始文件名和产品名称为"Astral"
- 在`main.cpp`中实现单实例应用逻辑并更新窗口标题为"Astral"
2025-03-18 21:00:17 +08:00

74 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"
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
const int bufferSize = 256;
wchar_t windowTitle[bufferSize];
if (GetWindowTextW(hwnd, windowTitle, bufferSize)) {
if (_wcsicmp(windowTitle, L"Astral") == 0) {
*((HWND*)lParam) = hwnd;
return FALSE;
}
}
return TRUE;
}
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
_In_ wchar_t *command_line, _In_ int show_command) {
HANDLE hMutex = CreateMutexW(NULL, TRUE, L"AstralAppSingleInstanceMutex");
if (GetLastError() == ERROR_ALREADY_EXISTS) {
HWND hWnd = NULL;
EnumWindows(EnumWindowsProc, (LPARAM)&hWnd);
if (hWnd != NULL) {
if (IsIconic(hWnd)) {
ShowWindow(hWnd, SW_RESTORE);
}
SetForegroundWindow(hWnd);
}
CloseHandle(hMutex);
return 0;
}
// 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);
if (!window.Create(L"Astral", origin, size)) {
return EXIT_FAILURE;
}
window.SetQuitOnClose(true);
::MSG msg;
while (::GetMessage(&msg, nullptr, 0, 0)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
CloseHandle(hMutex);
return EXIT_SUCCESS;
}