diff --git a/winit-win32/src/window_state.rs b/winit-win32/src/window_state.rs index 01461a89..27b00784 100644 --- a/winit-win32/src/window_state.rs +++ b/winit-win32/src/window_state.rs @@ -332,9 +332,6 @@ impl WindowFlags { if self.contains(WindowFlags::VISIBLE) { style |= WS_VISIBLE; } - if self.contains(WindowFlags::ALWAYS_ON_TOP) { - style_ex |= WS_EX_TOPMOST; - } if self.contains(WindowFlags::NO_BACK_BUFFER) { style_ex |= WS_EX_NOREDIRECTIONBITMAP; } @@ -366,6 +363,19 @@ impl WindowFlags { style &= !WS_OVERLAPPEDWINDOW; } + if self.contains(WindowFlags::ALWAYS_ON_TOP) { + style_ex |= WS_EX_TOPMOST; + + // A window with WS_EX_TOPMOST set must have one of the following style flags: + // WS_POPUP, WS_BORDER, WS_CAPTION, WS_SYSMENU, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, + // WS_THICKFRAME, WS_EX_CLIENTEDGE, WS_EX_CONTEXTHELP, WS_EX_DLGMODALFRAME, + // WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE. + // If none of them are set, it will cause a DXGI error when creating a swapchain. + if style & WS_CAPTION == 0 { + style |= WS_POPUP; + } + } + (style, style_ex) } diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index f3a0f6d2..2b463b16 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -39,3 +39,7 @@ The migration guide could reference other migration examples in the current changelog entry. ## Unreleased + +### Fixed + +- On Windows, fix a crash occurring when trying to create a DXGI surface on a window that is both fullscreen and always on top.