Skip to content

Commit 923dcd3

Browse files
committed
Refactor Windows runner to remove custom window classes
Deleted custom Win32Window and FlutterWindow implementations, updating CMakeLists and main.cpp to use FlutterEngine directly. This simplifies the Windows runner code and removes unnecessary abstraction layers, relying on the Flutter engine for window management.
1 parent 22ddf4a commit 923dcd3

9 files changed

Lines changed: 9 additions & 514 deletions

File tree

examples/multiple_window_example/windows/flutter/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
cmake_minimum_required(VERSION 3.14)
33

44
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5+
set(CMAKE_CXX_STANDARD 20)
56

67
# Configuration provided via flutter tool.
78
include(${EPHEMERAL_DIR}/generated_config.cmake)
@@ -51,7 +52,6 @@ list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
5152
list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
5253
list(APPEND CPP_WRAPPER_SOURCES_APP
5354
"flutter_engine.cc"
54-
"flutter_view_controller.cc"
5555
)
5656
list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
5757

examples/multiple_window_example/windows/runner/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ project(runner LANGUAGES CXX)
77
#
88
# Any new source files that you add to the application should be added here.
99
add_executable(${BINARY_NAME} WIN32
10-
"flutter_window.cpp"
1110
"main.cpp"
1211
"utils.cpp"
13-
"win32_window.cpp"
1412
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
1513
"Runner.rc"
1614
"runner.exe.manifest"
@@ -33,7 +31,6 @@ target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
3331
# Add dependency libraries and include directories. Add any application-specific
3432
# dependencies here.
3533
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
36-
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
3734
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
3835

3936
# Run the Flutter tool portions of the build. This must not be removed.

examples/multiple_window_example/windows/runner/flutter_window.cpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

examples/multiple_window_example/windows/runner/flutter_window.h

Lines changed: 0 additions & 33 deletions
This file was deleted.

examples/multiple_window_example/windows/runner/main.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include <flutter/dart_project.h>
2-
#include <flutter/flutter_view_controller.h>
3-
#include <windows.h>
2+
#include <flutter/flutter_engine.h>
3+
#include <flutter/generated_plugin_registrant.h>
44

5-
#include "flutter_window.h"
65
#include "utils.h"
76

87
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9-
_In_ wchar_t *command_line, _In_ int show_command) {
8+
_In_ wchar_t* command_line, _In_ int show_command) {
109
// Attach to console when present (e.g., 'flutter run') or create a
1110
// new console when running with a debugger.
1211
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
@@ -19,18 +18,13 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
1918

2019
flutter::DartProject project(L"data");
2120

22-
std::vector<std::string> command_line_arguments =
23-
GetCommandLineArguments();
21+
auto command_line_arguments{GetCommandLineArguments()};
2422

2523
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
2624

27-
FlutterWindow window(project);
28-
Win32Window::Point origin(10, 10);
29-
Win32Window::Size size(1280, 720);
30-
if (!window.Create(L"multiple_window_example", origin, size)) {
31-
return EXIT_FAILURE;
32-
}
33-
window.SetQuitOnClose(true);
25+
auto const engine{std::make_shared<flutter::FlutterEngine>(project)};
26+
RegisterPlugins(engine.get());
27+
engine->Run();
3428

3529
::MSG msg;
3630
while (::GetMessage(&msg, nullptr, 0, 0)) {

examples/multiple_window_example/windows/runner/resource.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Microsoft Visual C++ generated include file.
33
// Used by Runner.rc
44
//
5-
#define IDI_APP_ICON 101
65

76
// Next default values for new objects
87
//

examples/multiple_window_example/windows/runner/utils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,14 @@ std::string Utf8FromUtf16(const wchar_t* utf16_string) {
4949
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
5050
-1, nullptr, 0, nullptr, nullptr)
5151
-1; // remove the trailing null character
52-
int input_length = (int)wcslen(utf16_string);
5352
std::string utf8_string;
5453
if (target_length == 0 || target_length > utf8_string.max_size()) {
5554
return utf8_string;
5655
}
5756
utf8_string.resize(target_length);
5857
int converted_length = ::WideCharToMultiByte(
5958
CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
60-
input_length, utf8_string.data(), target_length, nullptr, nullptr);
59+
-1, utf8_string.data(), target_length, nullptr, nullptr);
6160
if (converted_length == 0) {
6261
return std::string();
6362
}

0 commit comments

Comments
 (0)