From 42575d4a9979b0c880c00670f0165beed680175c Mon Sep 17 00:00:00 2001 From: Sven Balzer <4653051+Kodokuna@users.noreply.github.com> Date: Thu, 17 Sep 2020 02:58:23 +0200 Subject: [PATCH] Viewports, Backends: Win32: Fix toggling of ImGuiViewportFlags_TopMost (#3477) --- examples/imgui_impl_win32.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/imgui_impl_win32.cpp b/examples/imgui_impl_win32.cpp index 878efeeb..07a0c560 100644 --- a/examples/imgui_impl_win32.cpp +++ b/examples/imgui_impl_win32.cpp @@ -660,13 +660,19 @@ static void ImGui_ImplWin32_UpdateWindow(ImGuiViewport* viewport) // Only reapply the flags that have been changed from our point of view (as other flags are being modified by Windows) if (data->DwStyle != new_style || data->DwExStyle != new_ex_style) { + // (Optional) Update TopMost state if it changed _after_ creation + bool top_most_changed = (data->DwExStyle & WS_EX_TOPMOST) != (new_ex_style & WS_EX_TOPMOST); + HWND insert_after = top_most_changed ? ((viewport->Flags & ImGuiViewportFlags_TopMost) ? HWND_TOPMOST : HWND_NOTOPMOST) : 0; + UINT swp_flag = top_most_changed ? 0 : SWP_NOZORDER; + + // Apply flags and position (since it is affected by flags) data->DwStyle = new_style; data->DwExStyle = new_ex_style; ::SetWindowLong(data->Hwnd, GWL_STYLE, data->DwStyle); ::SetWindowLong(data->Hwnd, GWL_EXSTYLE, data->DwExStyle); RECT rect = { (LONG)viewport->Pos.x, (LONG)viewport->Pos.y, (LONG)(viewport->Pos.x + viewport->Size.x), (LONG)(viewport->Pos.y + viewport->Size.y) }; ::AdjustWindowRectEx(&rect, data->DwStyle, FALSE, data->DwExStyle); // Client to Screen - ::SetWindowPos(data->Hwnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); + ::SetWindowPos(data->Hwnd, insert_after, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, swp_flag | SWP_NOACTIVATE | SWP_FRAMECHANGED); ::ShowWindow(data->Hwnd, SW_SHOWNA); // This is necessary when we alter the style viewport->PlatformRequestMove = viewport->PlatformRequestResize = true; }