From b9b4e662b40c2b88a13aad3812942a746b963056 Mon Sep 17 00:00:00 2001 From: shibayan Date: Tue, 19 Jan 2016 23:05:56 +0900 Subject: [PATCH] Change the condition to perform QuickLook --- src/WinQuickLook/App.xaml.cs | 19 +++++++++++-------- src/WinQuickLook/Interop/Consts.cs | 3 +++ src/WinQuickLook/Interop/NativeMethods.cs | 6 ++++++ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/WinQuickLook/App.xaml.cs b/src/WinQuickLook/App.xaml.cs index 2d35d13a..ddde8def 100644 --- a/src/WinQuickLook/App.xaml.cs +++ b/src/WinQuickLook/App.xaml.cs @@ -12,6 +12,8 @@ public partial class App private QuickLookWindow _quickLookWindow; + private string _currentItem; + protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); @@ -52,20 +54,21 @@ private void CancelQuickLook() private void PerformQuickLook() { - if (_quickLookWindow?.CloseIfActive() ?? false) - { - _quickLookWindow = null; - - return; - } - var selectedItem = WinExplorerHelper.GetSelectedItem(); - if (selectedItem == null) + if (selectedItem == null || selectedItem == _currentItem) { + if (_quickLookWindow?.CloseIfActive() ?? false) + { + _currentItem = null; + _quickLookWindow = null; + } + return; } + _currentItem = selectedItem; + _quickLookWindow?.Close(); _quickLookWindow = null; diff --git a/src/WinQuickLook/Interop/Consts.cs b/src/WinQuickLook/Interop/Consts.cs index f8a8804d..0789dcea 100644 --- a/src/WinQuickLook/Interop/Consts.cs +++ b/src/WinQuickLook/Interop/Consts.cs @@ -9,6 +9,9 @@ public static class Consts public const int WM_KEYDOWN = 0x0100; public const int MAX_PATH = 260; + + public const int GWL_EXSTYLE = -20; + public const int WS_EX_NOACTIVATE = 0x8000000; } [Flags] diff --git a/src/WinQuickLook/Interop/NativeMethods.cs b/src/WinQuickLook/Interop/NativeMethods.cs index c5dd63f7..a23afdcf 100644 --- a/src/WinQuickLook/Interop/NativeMethods.cs +++ b/src/WinQuickLook/Interop/NativeMethods.cs @@ -24,6 +24,12 @@ public static class NativeMethods [DllImport("user32.dll")] public static extern IntPtr CallNextHookEx(IntPtr hook, int nCode, IntPtr wParam, IntPtr lParam); + [DllImport("user32.dll")] + public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); + + [DllImport("user32.dll")] + public static extern int GetWindowLong(IntPtr hWnd, int nIndex); + [DllImport("gdi32.dll")] public static extern bool DeleteObject(IntPtr hObject);