diff --git a/src/win/window.rs b/src/win/window.rs index f86b1c27..4ab4f4d4 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -512,7 +512,7 @@ pub(super) struct WindowState { window_class: Cell>, current_size: Cell, current_scale_factor: Cell, - _parent_handle: Option, + _parent_handle: ParentHandle, keyboard_state: RefCell, mouse_button_counter: Cell, mouse_was_outside_window: RefCell, @@ -632,13 +632,13 @@ impl Window<'_> { B: FnOnce(&mut crate::Window) -> H, B: Send + 'static, { - let (_, hwnd) = Self::open(false, null_mut(), options, build); + let (window_handle, _) = Self::open(false, null_mut(), options, build); unsafe { let mut msg: MSG = std::mem::zeroed(); loop { - let status = GetMessageW(&mut msg, hwnd, 0, 0); + let status = GetMessageW(&mut msg, null_mut(), 0, 0); if status == -1 { break; @@ -646,6 +646,10 @@ impl Window<'_> { TranslateMessage(&msg); DispatchMessageW(&msg); + + if !window_handle.is_open() { + break; + } } } } @@ -725,7 +729,6 @@ impl Window<'_> { }); let (parent_handle, window_handle) = ParentHandle::new(hwnd); - let parent_handle = if parented { Some(parent_handle) } else { None }; let window_state = Rc::new(WindowState { hwnd,