Skip to content

Commit

Permalink
Fix QL-Win#644: still use focusable window on Windows 7 and 8
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed May 16, 2020
1 parent b2fdd05 commit 452574e
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions QuickLook/ViewerWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using QuickLook.Common.ExtensionMethods;
using QuickLook.Common.Helpers;
using QuickLook.Common.Plugin;
using QuickLook.Helpers;
using Brush = System.Windows.Media.Brush;
using FontFamily = System.Windows.Media.FontFamily;
using Size = System.Windows.Size;

namespace QuickLook
{
Expand Down Expand Up @@ -58,10 +56,12 @@ internal ViewerWindow()

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

windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;

Topmost = SettingHelper.Get("Topmost", false);
buttonTop.Tag = Topmost ? "Top" : "Auto";

Expand Down Expand Up @@ -108,20 +108,25 @@ protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);

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

HwndSource.FromHwnd(new WindowInteropHelper(this).Handle)?.AddHook(
(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
switch (msg)
HwndSource.FromHwnd(new WindowInteropHelper(this).Handle)?.AddHook(
(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
{
case 0x0112: // WM_SYSCOMMAND
this.BringToFront(false);
break;
}
return IntPtr.Zero;
});
switch (msg)
{
case 0x0112: // WM_SYSCOMMAND
this.BringToFront(false);
break;
}
return IntPtr.Zero;
});
}
}

public override void OnApplyTemplate()
Expand Down

0 comments on commit 452574e

Please sign in to comment.