Skip to content

Commit 452574e

Browse files
committed
Fix QL-Win#644: still use focusable window on Windows 7 and 8
1 parent b2fdd05 commit 452574e

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

QuickLook/ViewerWindow.xaml.cs

+22-17
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
using System.Windows;
2020
using System.Windows.Input;
2121
using System.Windows.Interop;
22+
using System.Windows.Media;
2223
using System.Windows.Media.Animation;
2324
using QuickLook.Common.ExtensionMethods;
2425
using QuickLook.Common.Helpers;
2526
using QuickLook.Common.Plugin;
2627
using QuickLook.Helpers;
27-
using Brush = System.Windows.Media.Brush;
28-
using FontFamily = System.Windows.Media.FontFamily;
29-
using Size = System.Windows.Size;
3028

3129
namespace QuickLook
3230
{
@@ -58,10 +56,12 @@ internal ViewerWindow()
5856

5957
// bring the window to top when users click in the client area.
6058
// the non-client area is handled by the WndProc inside OnSourceInitialized().
61-
PreviewMouseDown += (sender, e) => this.BringToFront(false);
59+
// This is buggy for Windows 7 and 8: https://github.com/QL-Win/QuickLook/issues/644#issuecomment-628921704
60+
if (App.IsWin10)
61+
PreviewMouseDown += (sender, e) => this.BringToFront(false);
6262

6363
windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;
64-
64+
6565
Topmost = SettingHelper.Get("Topmost", false);
6666
buttonTop.Tag = Topmost ? "Top" : "Auto";
6767

@@ -108,20 +108,25 @@ protected override void OnSourceInitialized(EventArgs e)
108108
{
109109
base.OnSourceInitialized(e);
110110

111-
this.SetNoactivate();
111+
// The non-focusable trick is buggy for Windows 7 and 8
112+
// https://github.com/QL-Win/QuickLook/issues/644#issuecomment-628921704
113+
if (App.IsWin10)
114+
{
115+
this.SetNoactivate();
112116

113-
HwndSource.FromHwnd(new WindowInteropHelper(this).Handle)?.AddHook(
114-
(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
115-
{
116-
switch (msg)
117+
HwndSource.FromHwnd(new WindowInteropHelper(this).Handle)?.AddHook(
118+
(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
117119
{
118-
case 0x0112: // WM_SYSCOMMAND
119-
this.BringToFront(false);
120-
break;
121-
}
122-
123-
return IntPtr.Zero;
124-
});
120+
switch (msg)
121+
{
122+
case 0x0112: // WM_SYSCOMMAND
123+
this.BringToFront(false);
124+
break;
125+
}
126+
127+
return IntPtr.Zero;
128+
});
129+
}
125130
}
126131

127132
public override void OnApplyTemplate()

0 commit comments

Comments
 (0)