From 3d11c9b1f724d40c70051f597f0d1ee4736662bf Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Sat, 23 Jun 2018 17:41:21 +0300 Subject: [PATCH] fix broken "keep in front" --- QuickLook.Common/Helpers/WindowHelper.cs | 8 +++++--- QuickLook/ViewerWindow.Actions.cs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/QuickLook.Common/Helpers/WindowHelper.cs b/QuickLook.Common/Helpers/WindowHelper.cs index dc10205..c5eac6b 100644 --- a/QuickLook.Common/Helpers/WindowHelper.cs +++ b/QuickLook.Common/Helpers/WindowHelper.cs @@ -42,13 +42,15 @@ namespace QuickLook.Common.Helpers new Size(screen.Width / scale.Horizontal, screen.Height / scale.Vertical)); } - public static void BringToFront(this Window window) + public static void BringToFront(this Window window, bool keep) { var handle = new WindowInteropHelper(window).Handle; User32.SetWindowPos(handle, User32.HWND_TOPMOST, 0, 0, 0, 0, User32.SWP_NOMOVE | User32.SWP_NOSIZE | User32.SWP_NOACTIVATE); - User32.SetWindowPos(handle, User32.HWND_NOTOPMOST, 0, 0, 0, 0, - User32.SWP_NOMOVE | User32.SWP_NOSIZE | User32.SWP_NOACTIVATE); + + if (!keep) + User32.SetWindowPos(handle, User32.HWND_NOTOPMOST, 0, 0, 0, 0, + User32.SWP_NOMOVE | User32.SWP_NOSIZE | User32.SWP_NOACTIVATE); } public static void MoveWindow(this Window window, diff --git a/QuickLook/ViewerWindow.Actions.cs b/QuickLook/ViewerWindow.Actions.cs index 1609a28..2523a5c 100644 --- a/QuickLook/ViewerWindow.Actions.cs +++ b/QuickLook/ViewerWindow.Actions.cs @@ -101,7 +101,7 @@ namespace QuickLook if (double.IsNaN(Left) || double.IsNaN(Top)) // first time showing WindowStartupLocation = WindowStartupLocation.CenterScreen; - Dispatcher.BeginInvoke(new Action(this.BringToFront), DispatcherPriority.Render); + Dispatcher.BeginInvoke(new Action(() => this.BringToFront(Topmost)), DispatcherPriority.Render); } }