From 71b5663483ddb218621c0dbfffbc5957395e3e5e Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 6 Nov 2023 14:51:49 +0200 Subject: [PATCH] impl drop on Windows --- src/webview2/mod.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/webview2/mod.rs b/src/webview2/mod.rs index 9a5e4e2bf..dccd19f7e 100644 --- a/src/webview2/mod.rs +++ b/src/webview2/mod.rs @@ -29,10 +29,11 @@ use windows::{ UI::{ Shell::{DefSubclassProc, SHCreateMemStream, SetWindowSubclass}, WindowsAndMessaging::{ - self as win32wm, CreateWindowExW, DefWindowProcW, PostMessageW, RegisterClassExW, - RegisterWindowMessageA, SetWindowPos, ShowWindow, CS_HREDRAW, CS_VREDRAW, CW_USEDEFAULT, - HCURSOR, HICON, HMENU, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOMOVE, SWP_NOSIZE, - SWP_NOZORDER, SW_HIDE, SW_SHOW, WINDOW_EX_STYLE, WNDCLASSEXW, WS_CHILD, WS_VISIBLE, + self as win32wm, CreateWindowExW, DefWindowProcW, DestroyWindow, PostMessageW, + RegisterClassExW, RegisterWindowMessageA, SetWindowPos, ShowWindow, CS_HREDRAW, CS_VREDRAW, + CW_USEDEFAULT, HCURSOR, HICON, HMENU, SWP_ASYNCWINDOWPOS, SWP_NOACTIVATE, SWP_NOMOVE, + SWP_NOSIZE, SWP_NOZORDER, SW_HIDE, SW_SHOW, WINDOW_EX_STYLE, WNDCLASSEXW, WS_CHILD, + WS_VISIBLE, }, }, }, @@ -63,6 +64,15 @@ pub(crate) struct InnerWebView { file_drop_controller: Option, } +impl Drop for InnerWebView { + fn drop(&mut self) { + let _ = unsafe { self.controller.Close() }; + if self.is_child { + let _ = unsafe { DestroyWindow(self.hwnd) }; + } + } +} + impl InnerWebView { pub fn new( window: &impl HasRawWindowHandle,