From b6fe78b82c339a7b3015bec1973c35daaac3a69a Mon Sep 17 00:00:00 2001 From: Nick Fisher Date: Wed, 23 Oct 2024 02:23:54 +1100 Subject: [PATCH] feat: (flutter) (windows) add Destroy() to BackingWindow --- .../windows/backing_window.cpp | 33 +++++++++++++++++++ .../thermion_flutter/windows/backing_window.h | 1 + 2 files changed, 34 insertions(+) diff --git a/thermion_flutter/thermion_flutter/windows/backing_window.cpp b/thermion_flutter/thermion_flutter/windows/backing_window.cpp index 573e70e4..8c3dee50 100644 --- a/thermion_flutter/thermion_flutter/windows/backing_window.cpp +++ b/thermion_flutter/thermion_flutter/windows/backing_window.cpp @@ -351,6 +351,39 @@ BackingWindow::BackingWindow(flutter::PluginRegistrarWindows *pluginRegistrar, ::SetWindowLong(_flutterRootWindow, GWL_EXSTYLE, ex_style); } +void BackingWindow::Destroy() { + if (_windowHandle) { + // Hide the window first + ::ShowWindow(_windowHandle, SW_HIDE); + + // Remove the window from taskbar if needed + ITaskbarList3* taskbar = nullptr; + if (SUCCEEDED(::CoCreateInstance(CLSID_TaskbarList, 0, CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(&taskbar)))) { + taskbar->DeleteTab(_windowHandle); + taskbar->Release(); + } + + // Clear any user data we set + ::SetWindowLongPtr(_windowHandle, GWLP_USERDATA, 0); + + // Destroy the window + ::DestroyWindow(_windowHandle); + _windowHandle = nullptr; + } + + // Clean up the window class registration + ::UnregisterClass(kClassName, GetModuleHandle(nullptr)); + + // Reset member variables + _flutterViewWindow = nullptr; + _flutterRootWindow = nullptr; + _width = 0; + _height = 0; + _left = 0; + _top = 0; +} + void BackingWindow::Resize(int width, int height, int left, int top) { _width = width; _height = height; diff --git a/thermion_flutter/thermion_flutter/windows/backing_window.h b/thermion_flutter/thermion_flutter/windows/backing_window.h index bf2cf0e7..56609f38 100644 --- a/thermion_flutter/thermion_flutter/windows/backing_window.h +++ b/thermion_flutter/thermion_flutter/windows/backing_window.h @@ -17,6 +17,7 @@ class BackingWindow { int top); HWND GetHandle(); void Resize(int width, int height, int left, int top); + void Destroy(); private: HWND _windowHandle; HWND _flutterRootWindow;