diff --git a/winit-win32/src/event_loop.rs b/winit-win32/src/event_loop.rs index ca29be1b..a4be8cca 100644 --- a/winit-win32/src/event_loop.rs +++ b/winit-win32/src/event_loop.rs @@ -1118,10 +1118,19 @@ unsafe fn lose_active_focus(window: HWND, userdata: &WindowData) { /// has to be done manually whenever `parent` receives a `WM_WINDOWPOSCHANGED` that moved it. unsafe fn reposition_owned_windows(parent: HWND) { unsafe extern "system" fn enum_proc(hwnd: HWND, lparam: LPARAM) -> BOOL { + use windows_sys::Win32::UI::WindowsAndMessaging::GWL_WNDPROC; + if unsafe { GetWindow(hwnd, GW_OWNER) } != lparam as HWND { return true.into(); // continue enumeration } + // Only winit's own windows keep a `WindowData` pointer in `GWL_USERDATA`, so skip any + // owned window that runs a different window procedure (dialogs, tooltips, helpers) + let window_proc = unsafe { util::get_window_long(hwnd, GWL_WNDPROC) }; + if window_proc != public_window_callback as *const () as isize { + return true.into(); // continue enumeration + } + let userdata_ptr = unsafe { util::get_window_long(hwnd, GWL_USERDATA) } as *mut WindowData; if !userdata_ptr.is_null() { let userdata = unsafe { &*userdata_ptr }; diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index 2a6b3728..a0e7d3a4 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -44,6 +44,7 @@ changelog entry. - On Windows, fix a crash occurring when trying to create a DXGI surface on a window that is both fullscreen and always on top. - On Wayland, use the touch serial for `Window::drag_window`, `Window::drag_resize_window` and `Window::show_window_menu` when the interaction was started by touch. +- On Windows, fix a crash when moving a window that owns windows not created by winit, such as native dialogs or application helper windows. ### Changed