diff --git a/dev/integration_tests/flutter_gallery/windows/runner/flutter_window.cpp b/dev/integration_tests/flutter_gallery/windows/runner/flutter_window.cpp index 9cbd3109c3..f68aa9c26c 100644 --- a/dev/integration_tests/flutter_gallery/windows/runner/flutter_window.cpp +++ b/dev/integration_tests/flutter_gallery/windows/runner/flutter_window.cpp @@ -30,6 +30,11 @@ bool FlutterWindow::OnCreate() { } RegisterPlugins(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + return true; } diff --git a/dev/integration_tests/flutter_gallery/windows/runner/main.cpp b/dev/integration_tests/flutter_gallery/windows/runner/main.cpp index 139eb1fa30..5afa6e1d16 100644 --- a/dev/integration_tests/flutter_gallery/windows/runner/main.cpp +++ b/dev/integration_tests/flutter_gallery/windows/runner/main.cpp @@ -31,7 +31,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"flutter_gallery", origin, size)) { + if (!window.Create(L"flutter_gallery", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/dev/integration_tests/flutter_gallery/windows/runner/win32_window.cpp b/dev/integration_tests/flutter_gallery/windows/runner/win32_window.cpp index 4021a2cfd4..635a5b29f5 100644 --- a/dev/integration_tests/flutter_gallery/windows/runner/win32_window.cpp +++ b/dev/integration_tests/flutter_gallery/windows/runner/win32_window.cpp @@ -106,9 +106,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -121,7 +121,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -133,6 +133,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, diff --git a/dev/integration_tests/flutter_gallery/windows/runner/win32_window.h b/dev/integration_tests/flutter_gallery/windows/runner/win32_window.h index 1dab1777c4..b161e9b84b 100644 --- a/dev/integration_tests/flutter_gallery/windows/runner/win32_window.h +++ b/dev/integration_tests/flutter_gallery/windows/runner/win32_window.h @@ -32,15 +32,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy(); diff --git a/dev/integration_tests/windows_startup_test/lib/main.dart b/dev/integration_tests/windows_startup_test/lib/main.dart index 6912089d18..e2d5d985ae 100644 --- a/dev/integration_tests/windows_startup_test/lib/main.dart +++ b/dev/integration_tests/windows_startup_test/lib/main.dart @@ -38,24 +38,32 @@ void main() async { const MethodChannel methodChannel = MethodChannel('tests.flutter.dev/windows_startup_test'); - // TODO(loic-sharma): Make the window invisible until after the first frame. - // https://github.com/flutter/flutter/issues/41980 final bool? visible = await methodChannel.invokeMethod('isWindowVisible'); - if (visible == null || visible == false) { - throw 'Window should be visible at startup'; + if (visible == null || visible == true) { + throw 'Window should be hidden at startup'; } + bool firstFrame = true; ui.PlatformDispatcher.instance.onBeginFrame = (Duration duration) async { final bool? visible = await methodChannel.invokeMethod('isWindowVisible'); - if (visible == null || visible == false) { - throw 'Window should be visible'; + if (visible == null) { + throw 'Method channel unavailable'; } - if (!completer.isCompleted) { - completer.complete('success'); + if (visible == true) { + if (firstFrame) { + throw 'Window should be hidden on first frame'; + } + + if (!completer.isCompleted) { + completer.complete('success'); + } } + // Draw something to trigger the first frame callback that displays the + // window. drawHelloWorld(); + firstFrame = false; }; ui.PlatformDispatcher.instance.scheduleFrame(); diff --git a/dev/integration_tests/windows_startup_test/windows/runner/flutter_window.cpp b/dev/integration_tests/windows_startup_test/windows/runner/flutter_window.cpp index f70a44e110..cb4c303856 100644 --- a/dev/integration_tests/windows_startup_test/windows/runner/flutter_window.cpp +++ b/dev/integration_tests/windows_startup_test/windows/runner/flutter_window.cpp @@ -5,6 +5,8 @@ #include "flutter_window.h" #include +#include + #include #include @@ -33,6 +35,16 @@ bool FlutterWindow::OnCreate() { RegisterPlugins(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + static std::mutex visible_mutex; + static bool visible = false; + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + std::scoped_lock lock(visible_mutex); + this->Show(); + visible = true; + }); + + // Create a method channel to check the window's visibility. flutter::MethodChannel<> channel( flutter_controller_->engine()->messenger(), "tests.flutter.dev/windows_startup_test", &flutter::StandardMethodCodec::GetInstance()); @@ -40,8 +52,9 @@ bool FlutterWindow::OnCreate() { channel.SetMethodCallHandler( [](const flutter::MethodCall<>& call, std::unique_ptr> result) { + std::scoped_lock lock(visible_mutex); if (call.method_name() == "isWindowVisible") { - result->Success(true); + result->Success(visible); } else { result->NotImplemented(); } diff --git a/dev/integration_tests/windows_startup_test/windows/runner/main.cpp b/dev/integration_tests/windows_startup_test/windows/runner/main.cpp index c251aca044..2bf0983c00 100644 --- a/dev/integration_tests/windows_startup_test/windows/runner/main.cpp +++ b/dev/integration_tests/windows_startup_test/windows/runner/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "flutter_window.h" #include "utils.h" @@ -31,7 +32,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"windows_startup_test", origin, size)) { + if (!window.Create(L"windows_startup_test", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/dev/integration_tests/windows_startup_test/windows/runner/win32_window.cpp b/dev/integration_tests/windows_startup_test/windows/runner/win32_window.cpp index 4021a2cfd4..635a5b29f5 100644 --- a/dev/integration_tests/windows_startup_test/windows/runner/win32_window.cpp +++ b/dev/integration_tests/windows_startup_test/windows/runner/win32_window.cpp @@ -106,9 +106,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -121,7 +121,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -133,6 +133,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, diff --git a/dev/integration_tests/windows_startup_test/windows/runner/win32_window.h b/dev/integration_tests/windows_startup_test/windows/runner/win32_window.h index 1dab1777c4..b161e9b84b 100644 --- a/dev/integration_tests/windows_startup_test/windows/runner/win32_window.h +++ b/dev/integration_tests/windows_startup_test/windows/runner/win32_window.h @@ -32,15 +32,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy(); diff --git a/dev/manual_tests/windows/runner/flutter_window.cpp b/dev/manual_tests/windows/runner/flutter_window.cpp index 9cbd3109c3..f68aa9c26c 100644 --- a/dev/manual_tests/windows/runner/flutter_window.cpp +++ b/dev/manual_tests/windows/runner/flutter_window.cpp @@ -30,6 +30,11 @@ bool FlutterWindow::OnCreate() { } RegisterPlugins(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + return true; } diff --git a/dev/manual_tests/windows/runner/main.cpp b/dev/manual_tests/windows/runner/main.cpp index 5bd83f75ab..e9efa2edb3 100644 --- a/dev/manual_tests/windows/runner/main.cpp +++ b/dev/manual_tests/windows/runner/main.cpp @@ -31,7 +31,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"manual_tests", origin, size)) { + if (!window.Create(L"manual_tests", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/dev/manual_tests/windows/runner/win32_window.cpp b/dev/manual_tests/windows/runner/win32_window.cpp index 4021a2cfd4..635a5b29f5 100644 --- a/dev/manual_tests/windows/runner/win32_window.cpp +++ b/dev/manual_tests/windows/runner/win32_window.cpp @@ -106,9 +106,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -121,7 +121,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -133,6 +133,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, diff --git a/dev/manual_tests/windows/runner/win32_window.h b/dev/manual_tests/windows/runner/win32_window.h index 1dab1777c4..b161e9b84b 100644 --- a/dev/manual_tests/windows/runner/win32_window.h +++ b/dev/manual_tests/windows/runner/win32_window.h @@ -32,15 +32,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy(); diff --git a/examples/flutter_view/windows/runner/flutter_window.cpp b/examples/flutter_view/windows/runner/flutter_window.cpp index 9cbd3109c3..f68aa9c26c 100644 --- a/examples/flutter_view/windows/runner/flutter_window.cpp +++ b/examples/flutter_view/windows/runner/flutter_window.cpp @@ -30,6 +30,11 @@ bool FlutterWindow::OnCreate() { } RegisterPlugins(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + return true; } diff --git a/examples/flutter_view/windows/runner/main.cpp b/examples/flutter_view/windows/runner/main.cpp index 855a36a55e..6e195d3838 100644 --- a/examples/flutter_view/windows/runner/main.cpp +++ b/examples/flutter_view/windows/runner/main.cpp @@ -31,7 +31,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"flutter_view", origin, size)) { + if (!window.Create(L"flutter_view", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/examples/flutter_view/windows/runner/win32_window.cpp b/examples/flutter_view/windows/runner/win32_window.cpp index 4021a2cfd4..635a5b29f5 100644 --- a/examples/flutter_view/windows/runner/win32_window.cpp +++ b/examples/flutter_view/windows/runner/win32_window.cpp @@ -106,9 +106,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -121,7 +121,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -133,6 +133,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, diff --git a/examples/flutter_view/windows/runner/win32_window.h b/examples/flutter_view/windows/runner/win32_window.h index 1dab1777c4..b161e9b84b 100644 --- a/examples/flutter_view/windows/runner/win32_window.h +++ b/examples/flutter_view/windows/runner/win32_window.h @@ -32,15 +32,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy(); diff --git a/examples/hello_world/windows/runner/flutter_window.cpp b/examples/hello_world/windows/runner/flutter_window.cpp index 9cbd3109c3..f68aa9c26c 100644 --- a/examples/hello_world/windows/runner/flutter_window.cpp +++ b/examples/hello_world/windows/runner/flutter_window.cpp @@ -30,6 +30,11 @@ bool FlutterWindow::OnCreate() { } RegisterPlugins(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + return true; } diff --git a/examples/hello_world/windows/runner/main.cpp b/examples/hello_world/windows/runner/main.cpp index 38cfc87ad4..b99d1968ae 100644 --- a/examples/hello_world/windows/runner/main.cpp +++ b/examples/hello_world/windows/runner/main.cpp @@ -31,7 +31,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"hello_world", origin, size)) { + if (!window.Create(L"hello_world", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/examples/hello_world/windows/runner/win32_window.cpp b/examples/hello_world/windows/runner/win32_window.cpp index 20c47eacec..9338467d48 100644 --- a/examples/hello_world/windows/runner/win32_window.cpp +++ b/examples/hello_world/windows/runner/win32_window.cpp @@ -106,9 +106,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -121,7 +121,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -133,6 +133,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, diff --git a/examples/hello_world/windows/runner/win32_window.h b/examples/hello_world/windows/runner/win32_window.h index 1dab1777c4..b161e9b84b 100644 --- a/examples/hello_world/windows/runner/win32_window.h +++ b/examples/hello_world/windows/runner/win32_window.h @@ -32,15 +32,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy(); diff --git a/examples/platform_channel/windows/runner/flutter_window.cpp b/examples/platform_channel/windows/runner/flutter_window.cpp index 3dec3e82d7..1d252ecf80 100644 --- a/examples/platform_channel/windows/runner/flutter_window.cpp +++ b/examples/platform_channel/windows/runner/flutter_window.cpp @@ -93,6 +93,11 @@ bool FlutterWindow::OnCreate() { })); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + return true; } diff --git a/examples/platform_channel/windows/runner/main.cpp b/examples/platform_channel/windows/runner/main.cpp index c52f49684e..1cadf8d747 100644 --- a/examples/platform_channel/windows/runner/main.cpp +++ b/examples/platform_channel/windows/runner/main.cpp @@ -30,7 +30,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"platform_channel", origin, size)) { + if (!window.Create(L"platform_channel", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/examples/platform_channel/windows/runner/win32_window.cpp b/examples/platform_channel/windows/runner/win32_window.cpp index 600749d7c1..87e7081db9 100644 --- a/examples/platform_channel/windows/runner/win32_window.cpp +++ b/examples/platform_channel/windows/runner/win32_window.cpp @@ -102,8 +102,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -116,7 +117,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -128,6 +129,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, const Point& origin, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, WPARAM const wparam, diff --git a/examples/platform_channel/windows/runner/win32_window.h b/examples/platform_channel/windows/runner/win32_window.h index 566ea77df3..23ed729660 100644 --- a/examples/platform_channel/windows/runner/win32_window.h +++ b/examples/platform_channel/windows/runner/win32_window.h @@ -32,14 +32,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy(); diff --git a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/flutter_window.cpp b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/flutter_window.cpp index b43b9095ea..b25e363efa 100644 --- a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/flutter_window.cpp +++ b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/flutter_window.cpp @@ -26,6 +26,11 @@ bool FlutterWindow::OnCreate() { } RegisterPlugins(flutter_controller_->engine()); SetChildContent(flutter_controller_->view()->GetNativeWindow()); + + flutter_controller_->engine()->SetNextFrameCallback([&]() { + this->Show(); + }); + return true; } diff --git a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/main.cpp.tmpl b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/main.cpp.tmpl index e944ed0079..70a53ab994 100644 --- a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/main.cpp.tmpl +++ b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/main.cpp.tmpl @@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.CreateAndShow(L"{{projectName}}", origin, size)) { + if (!window.Create(L"{{projectName}}", origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.cpp b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.cpp index 30b08cc8c9..c7bcb4df47 100644 --- a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.cpp +++ b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.cpp @@ -102,9 +102,9 @@ Win32Window::~Win32Window() { Destroy(); } -bool Win32Window::CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size) { +bool Win32Window::Create(const std::wstring& title, + const Point& origin, + const Size& size) { Destroy(); const wchar_t* window_class = @@ -117,7 +117,7 @@ bool Win32Window::CreateAndShow(const std::wstring& title, double scale_factor = dpi / 96.0; HWND window = CreateWindow( - window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + window_class, title.c_str(), WS_OVERLAPPEDWINDOW, Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), Scale(size.width, scale_factor), Scale(size.height, scale_factor), nullptr, nullptr, GetModuleHandle(nullptr), this); @@ -129,6 +129,10 @@ bool Win32Window::CreateAndShow(const std::wstring& title, return OnCreate(); } +bool Win32Window::Show() { + return ShowWindow(window_handle_, SW_SHOWNORMAL); +} + // static LRESULT CALLBACK Win32Window::WndProc(HWND const window, UINT const message, diff --git a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.h b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.h index 17ba431125..a4b8f1f0ef 100644 --- a/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.h +++ b/packages/flutter_tools/templates/app_shared/windows.tmpl/runner/win32_window.h @@ -28,15 +28,16 @@ class Win32Window { Win32Window(); virtual ~Win32Window(); - // Creates and shows a win32 window with |title| and position and size using + // Creates a win32 window with |title| that is positioned and sized using // |origin| and |size|. New windows are created on the default monitor. Window // sizes are specified to the OS in physical pixels, hence to ensure a - // consistent size to will treat the width height passed in to this function - // as logical pixels and scale to appropriate for the default monitor. Returns - // true if the window was created successfully. - bool CreateAndShow(const std::wstring& title, - const Point& origin, - const Size& size); + // consistent size this function will scale the inputted width and height as + // as appropriate for the default monitor. The window is invisible until + // |Show| is called. Returns true if the window was created successfully. + bool Create(const std::wstring& title, const Point& origin, const Size& size); + + // Show the current window. Returns true if the window was successfully shown. + bool Show(); // Release OS resources associated with window. void Destroy();