|
18 | 18 | using System;
|
19 | 19 | using System.Windows;
|
20 | 20 | using System.Windows.Input;
|
| 21 | +using System.Windows.Interop; |
21 | 22 | using System.Windows.Media.Animation;
|
22 | 23 | using QuickLook.Common.ExtensionMethods;
|
23 | 24 | using QuickLook.Common.Helpers;
|
@@ -55,16 +56,15 @@ internal ViewerWindow()
|
55 | 56 |
|
56 | 57 | StateChanged += (sender, e) => _ignoreNextWindowSizeChange = true;
|
57 | 58 |
|
| 59 | + // bring the window to top when users click in the client area. |
| 60 | + // the non-client area is handled by the WndProc inside OnSourceInitialized(). |
| 61 | + PreviewMouseDown += (sender, e) => this.BringToFront(false); |
| 62 | + |
58 | 63 | windowFrameContainer.PreviewMouseMove += ShowWindowCaptionContainer;
|
59 | 64 |
|
60 | 65 | Topmost = SettingHelper.Get("Topmost", false);
|
61 | 66 | buttonTop.Tag = Topmost ? "Top" : "Auto";
|
62 | 67 |
|
63 |
| - SourceInitialized += (sender, e) => this.SetNoactivate(); |
64 |
| - |
65 |
| - // bring the window to top. use together with SetNoactivate() |
66 |
| - PreviewMouseDown += (sender, e) => this.BringToFront(false); |
67 |
| - |
68 | 68 | buttonTop.Click += (sender, e) =>
|
69 | 69 | {
|
70 | 70 | Topmost = !Topmost;
|
@@ -103,6 +103,27 @@ internal ViewerWindow()
|
103 | 103 | buttonOpenWith.Click += (sender, e) => ShareHelper.Share(_path, this, true);
|
104 | 104 | }
|
105 | 105 |
|
| 106 | + // bring the window to top when users click in the non-client area. |
| 107 | + protected override void OnSourceInitialized(EventArgs e) |
| 108 | + { |
| 109 | + base.OnSourceInitialized(e); |
| 110 | + |
| 111 | + this.SetNoactivate(); |
| 112 | + |
| 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 | + { |
| 118 | + case 0x0112: // WM_SYSCOMMAND |
| 119 | + this.BringToFront(false); |
| 120 | + break; |
| 121 | + } |
| 122 | + |
| 123 | + return IntPtr.Zero; |
| 124 | + }); |
| 125 | + } |
| 126 | + |
106 | 127 | public override void OnApplyTemplate()
|
107 | 128 | {
|
108 | 129 | base.OnApplyTemplate();
|
|
0 commit comments