From 1b2f5fabfab2d955aca31f126eb84593a2029a85 Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Sun, 15 Oct 2017 18:04:22 +0300 Subject: [PATCH] Fix #101: Do not preview when Listary toolbar is visible --- .../QuickLook.Native32/HelperMethods.cpp | 30 +++++++++++++++++-- .../QuickLook.Native32/HelperMethods.h | 3 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp index 2c35b27..f299ac6 100644 --- a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp +++ b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp @@ -63,18 +63,44 @@ void HelperMethods::ObtainFirstItem(CComPtr dao, PWCHAR buffer) DragQueryFile(HDROP(medium.hGlobal), 0, buffer, MAX_PATH - 1); } +bool HelperMethods::IsListaryToolbarVisible() +{ + auto CALLBACK findListaryWindowProc = [](__in HWND hwnd, __in LPARAM lParam)-> BOOL + { + WCHAR classBuffer[MAX_PATH] = {'\0'}; + if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH))) + return TRUE; + + if (wcsncmp(classBuffer, L"Listary_WidgetWin_", 18) == 0) + { + if (IsWindowVisible(hwnd)) + { + *reinterpret_cast(lParam) = true; + return FALSE; + } + } + return TRUE; + }; + + auto found = false; + EnumWindows(findListaryWindowProc, reinterpret_cast(&found)); + + return found; +} + bool HelperMethods::IsCursorActivated(HWND hwnd) { auto tId = GetWindowThreadProcessId(hwnd, nullptr); GUITHREADINFO gui = {sizeof gui}; GetGUIThreadInfo(tId, &gui); - return gui.flags || gui.hwndCaret; + return gui.flags || gui.hwndCaret || IsListaryToolbarVisible(); } bool HelperMethods::IsUWP() { - auto pGCPFN = decltype(&GetCurrentPackageFullName)(GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetCurrentPackageFullName")); + auto pGCPFN = decltype(&GetCurrentPackageFullName)( + GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetCurrentPackageFullName")); if (!pGCPFN) return false; diff --git a/QuickLook.Native/QuickLook.Native32/HelperMethods.h b/QuickLook.Native/QuickLook.Native32/HelperMethods.h index 73c1eac..351c50c 100644 --- a/QuickLook.Native/QuickLook.Native32/HelperMethods.h +++ b/QuickLook.Native/QuickLook.Native32/HelperMethods.h @@ -23,4 +23,7 @@ public: static void ObtainFirstItem(CComPtr dao, PWCHAR buffer); static bool IsCursorActivated(HWND hwndfg); static bool HelperMethods::IsUWP(); + +private: + static bool IsListaryToolbarVisible(); };