Skip to content

Commit 94b3128

Browse files
authored
Add files via upload
1 parent d836bd9 commit 94b3128

File tree

15 files changed

+818
-0
lines changed

15 files changed

+818
-0
lines changed

windows/runner/CMakeLists.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(runner LANGUAGES CXX)
3+
4+
# Define the application target. To change its name, change BINARY_NAME in the
5+
# top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6+
# work.
7+
#
8+
# Any new source files that you add to the application should be added here.
9+
add_executable(${BINARY_NAME} WIN32
10+
"flutter_window.cpp"
11+
"main.cpp"
12+
"utils.cpp"
13+
"win32_window.cpp"
14+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
15+
"Runner.rc"
16+
"runner.exe.manifest"
17+
)
18+
19+
# Apply the standard set of build settings. This can be removed for applications
20+
# that need different build settings.
21+
apply_standard_settings(${BINARY_NAME})
22+
23+
# Add preprocessor definitions for the build version.
24+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
25+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
26+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
27+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
28+
target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
29+
30+
# Disable Windows macros that collide with C++ standard library functions.
31+
target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
32+
33+
# Add dependency libraries and include directories. Add any application-specific
34+
# dependencies here.
35+
target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
36+
target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
37+
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
38+
39+
# Run the Flutter tool portions of the build. This must not be removed.
40+
add_dependencies(${BINARY_NAME} flutter_assemble)

windows/runner/RCa03756

6.35 KB
Binary file not shown.

windows/runner/RCa13476

6.35 KB
Binary file not shown.

windows/runner/RCa14012

6.35 KB
Binary file not shown.

windows/runner/Runner.rc

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Microsoft Visual C++ generated resource script.
2+
//
3+
#pragma code_page(65001)
4+
#include "resource.h"
5+
6+
#define APSTUDIO_READONLY_SYMBOLS
7+
/////////////////////////////////////////////////////////////////////////////
8+
//
9+
// Generated from the TEXTINCLUDE 2 resource.
10+
//
11+
#include "winres.h"
12+
13+
/////////////////////////////////////////////////////////////////////////////
14+
#undef APSTUDIO_READONLY_SYMBOLS
15+
16+
/////////////////////////////////////////////////////////////////////////////
17+
// English (United States) resources
18+
19+
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20+
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21+
22+
#ifdef APSTUDIO_INVOKED
23+
/////////////////////////////////////////////////////////////////////////////
24+
//
25+
// TEXTINCLUDE
26+
//
27+
28+
1 TEXTINCLUDE
29+
BEGIN
30+
"resource.h\0"
31+
END
32+
33+
2 TEXTINCLUDE
34+
BEGIN
35+
"#include ""winres.h""\r\n"
36+
"\0"
37+
END
38+
39+
3 TEXTINCLUDE
40+
BEGIN
41+
"\r\n"
42+
"\0"
43+
END
44+
45+
#endif // APSTUDIO_INVOKED
46+
47+
48+
/////////////////////////////////////////////////////////////////////////////
49+
//
50+
// Icon
51+
//
52+
53+
// Icon with lowest ID value placed first to ensure application icon
54+
// remains consistent on all systems.
55+
IDI_APP_ICON ICON "resources\\app_icon1.ico"
56+
57+
58+
/////////////////////////////////////////////////////////////////////////////
59+
//
60+
// Version
61+
//
62+
63+
#if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64+
#define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
65+
#else
66+
#define VERSION_AS_NUMBER 1,0,0,0
67+
#endif
68+
69+
#if defined(FLUTTER_VERSION)
70+
#define VERSION_AS_STRING FLUTTER_VERSION
71+
#else
72+
#define VERSION_AS_STRING "1.0.0"
73+
#endif
74+
75+
VS_VERSION_INFO VERSIONINFO
76+
FILEVERSION VERSION_AS_NUMBER
77+
PRODUCTVERSION VERSION_AS_NUMBER
78+
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79+
#ifdef _DEBUG
80+
FILEFLAGS VS_FF_DEBUG
81+
#else
82+
FILEFLAGS 0x0L
83+
#endif
84+
FILEOS VOS__WINDOWS32
85+
FILETYPE VFT_APP
86+
FILESUBTYPE 0x0L
87+
BEGIN
88+
BLOCK "StringFileInfo"
89+
BEGIN
90+
BLOCK "040904e4"
91+
BEGIN
92+
VALUE "CompanyName", "com.example" "\0"
93+
VALUE "FileDescription", "dog_classifier" "\0"
94+
VALUE "FileVersion", VERSION_AS_STRING "\0"
95+
VALUE "InternalName", "dog_classifier" "\0"
96+
VALUE "LegalCopyright", "Copyright (C) 2023 com.example. All rights reserved." "\0"
97+
VALUE "OriginalFilename", "dog_classifier.exe" "\0"
98+
VALUE "ProductName", "dog_classifier" "\0"
99+
VALUE "ProductVersion", VERSION_AS_STRING "\0"
100+
END
101+
END
102+
BLOCK "VarFileInfo"
103+
BEGIN
104+
VALUE "Translation", 0x409, 1252
105+
END
106+
END
107+
108+
#endif // English (United States) resources
109+
/////////////////////////////////////////////////////////////////////////////
110+
111+
112+
113+
#ifndef APSTUDIO_INVOKED
114+
/////////////////////////////////////////////////////////////////////////////
115+
//
116+
// Generated from the TEXTINCLUDE 3 resource.
117+
//
118+
119+
120+
/////////////////////////////////////////////////////////////////////////////
121+
#endif // not APSTUDIO_INVOKED

windows/runner/flutter_window.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "flutter_window.h"
2+
3+
#include <optional>
4+
5+
#include "flutter/generated_plugin_registrant.h"
6+
7+
FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8+
: project_(project) {}
9+
10+
FlutterWindow::~FlutterWindow() {}
11+
12+
bool FlutterWindow::OnCreate() {
13+
if (!Win32Window::OnCreate()) {
14+
return false;
15+
}
16+
17+
RECT frame = GetClientArea();
18+
19+
// The size here must match the window dimensions to avoid unnecessary surface
20+
// creation / destruction in the startup path.
21+
flutter_controller_ = std::make_unique<flutter::FlutterViewController>(
22+
frame.right - frame.left, frame.bottom - frame.top, project_);
23+
// Ensure that basic setup of the controller was successful.
24+
if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25+
return false;
26+
}
27+
RegisterPlugins(flutter_controller_->engine());
28+
SetChildContent(flutter_controller_->view()->GetNativeWindow());
29+
30+
flutter_controller_->engine()->SetNextFrameCallback([&]() {
31+
this->Show();
32+
});
33+
34+
// Flutter can complete the first frame before the "show window" callback is
35+
// registered. The following call ensures a frame is pending to ensure the
36+
// window is shown. It is a no-op if the first frame hasn't completed yet.
37+
flutter_controller_->ForceRedraw();
38+
39+
return true;
40+
}
41+
42+
void FlutterWindow::OnDestroy() {
43+
if (flutter_controller_) {
44+
flutter_controller_ = nullptr;
45+
}
46+
47+
Win32Window::OnDestroy();
48+
}
49+
50+
LRESULT
51+
FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
52+
WPARAM const wparam,
53+
LPARAM const lparam) noexcept {
54+
// Give Flutter, including plugins, an opportunity to handle window messages.
55+
if (flutter_controller_) {
56+
std::optional<LRESULT> result =
57+
flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
58+
lparam);
59+
if (result) {
60+
return *result;
61+
}
62+
}
63+
64+
switch (message) {
65+
case WM_FONTCHANGE:
66+
flutter_controller_->engine()->ReloadSystemFonts();
67+
break;
68+
}
69+
70+
return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
71+
}

windows/runner/flutter_window.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef RUNNER_FLUTTER_WINDOW_H_
2+
#define RUNNER_FLUTTER_WINDOW_H_
3+
4+
#include <flutter/dart_project.h>
5+
#include <flutter/flutter_view_controller.h>
6+
7+
#include <memory>
8+
9+
#include "win32_window.h"
10+
11+
// A window that does nothing but host a Flutter view.
12+
class FlutterWindow : public Win32Window {
13+
public:
14+
// Creates a new FlutterWindow hosting a Flutter view running |project|.
15+
explicit FlutterWindow(const flutter::DartProject& project);
16+
virtual ~FlutterWindow();
17+
18+
protected:
19+
// Win32Window:
20+
bool OnCreate() override;
21+
void OnDestroy() override;
22+
LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
23+
LPARAM const lparam) noexcept override;
24+
25+
private:
26+
// The project to run.
27+
flutter::DartProject project_;
28+
29+
// The Flutter instance hosted by this window.
30+
std::unique_ptr<flutter::FlutterViewController> flutter_controller_;
31+
};
32+
33+
#endif // RUNNER_FLUTTER_WINDOW_H_

windows/runner/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <flutter/dart_project.h>
2+
#include <flutter/flutter_view_controller.h>
3+
#include <windows.h>
4+
5+
#include "flutter_window.h"
6+
#include "utils.h"
7+
8+
int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9+
_In_ wchar_t *command_line, _In_ int show_command) {
10+
// Attach to console when present (e.g., 'flutter run') or create a
11+
// new console when running with a debugger.
12+
if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
13+
CreateAndAttachConsole();
14+
}
15+
16+
// Initialize COM, so that it is available for use in the library and/or
17+
// plugins.
18+
::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
19+
20+
flutter::DartProject project(L"data");
21+
22+
std::vector<std::string> command_line_arguments =
23+
GetCommandLineArguments();
24+
25+
project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
26+
27+
FlutterWindow window(project);
28+
Win32Window::Point origin(10, 10);
29+
Win32Window::Size size(1280, 720);
30+
if (!window.Create(L"dog_classifier", origin, size)) {
31+
return EXIT_FAILURE;
32+
}
33+
window.SetQuitOnClose(true);
34+
35+
::MSG msg;
36+
while (::GetMessage(&msg, nullptr, 0, 0)) {
37+
::TranslateMessage(&msg);
38+
::DispatchMessage(&msg);
39+
}
40+
41+
::CoUninitialize();
42+
return EXIT_SUCCESS;
43+
}

windows/runner/resource.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//{{NO_DEPENDENCIES}}
2+
// Microsoft Visual C++ generated include file.
3+
// Used by Runner.rc
4+
//
5+
#define IDI_APP_ICON 101
6+
7+
// Next default values for new objects
8+
//
9+
#ifdef APSTUDIO_INVOKED
10+
#ifndef APSTUDIO_READONLY_SYMBOLS
11+
#define _APS_NEXT_RESOURCE_VALUE 102
12+
#define _APS_NEXT_COMMAND_VALUE 40001
13+
#define _APS_NEXT_CONTROL_VALUE 1001
14+
#define _APS_NEXT_SYMED_VALUE 101
15+
#endif
16+
#endif
4.19 KB
Binary file not shown.

0 commit comments

Comments
 (0)