diff --git a/QuickLook.Common b/QuickLook.Common index 5c035caf..e8c5ecbe 160000 --- a/QuickLook.Common +++ b/QuickLook.Common @@ -1 +1 @@ -Subproject commit 5c035caf526ea90f9b2b6d15a9d7bbb5a9cd0b68 +Subproject commit e8c5ecbe4cabbafe3ec794aa57d64e45b1b5eb2b diff --git a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp index f299ac63..92b595e0 100644 --- a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp +++ b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp @@ -88,13 +88,41 @@ bool HelperMethods::IsListaryToolbarVisible() return found; } +// Windows 10 1909 replaced the search box in the File Explorer by a UWP control. +// gti.flags is always 0 for UWP applications. +bool HelperMethods::IsSearchBoxFocused() +{ + WCHAR wClassBuffer[MAX_PATH] = { '\0' }; + if (FAILED(GetClassName(GetForegroundWindow(), wClassBuffer, MAX_PATH))) + return false; + + if (wcscmp(wClassBuffer, L"ExploreWClass") != 0 && wcscmp(wClassBuffer, L"CabinetWClass") != 0) + return false; + + auto* hwnd = GetFocusedControl(); + + WCHAR classBuffer[MAX_PATH] = { '\0' }; + if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH))) + return false; + + if (wcscmp(classBuffer, L"Windows.UI.Core.CoreWindow") != 0) + return false; + + WCHAR textBuffer[MAX_PATH] = { '\0' }; + if (FAILED(GetWindowText(hwnd, textBuffer, MAX_PATH))) + return false; + + return wcscmp(textBuffer, L"Cortana") == 0; +} + bool HelperMethods::IsCursorActivated(HWND hwnd) { auto tId = GetWindowThreadProcessId(hwnd, nullptr); - GUITHREADINFO gui = {sizeof gui}; - GetGUIThreadInfo(tId, &gui); - return gui.flags || gui.hwndCaret || IsListaryToolbarVisible(); + GUITHREADINFO gti = { sizeof gti }; + GetGUIThreadInfo(tId, >i); + + return gti.flags || gti.hwndCaret || IsSearchBoxFocused() || IsListaryToolbarVisible(); } bool HelperMethods::IsUWP() @@ -108,3 +136,17 @@ bool HelperMethods::IsUWP() UINT32 pn = 0; return pGCPFN(&pn, nullptr) == ERROR_INSUFFICIENT_BUFFER; } + +HWND HelperMethods::GetFocusedControl() +{ + auto tid = GetWindowThreadProcessId(GetForegroundWindow(), nullptr); + + if (0 == AttachThreadInput(GetCurrentThreadId(), tid, TRUE)) + return nullptr; + + auto* hwnd = GetFocus(); + + AttachThreadInput(GetCurrentThreadId(), tid, FALSE); + + return hwnd; +} diff --git a/QuickLook.Native/QuickLook.Native32/HelperMethods.h b/QuickLook.Native/QuickLook.Native32/HelperMethods.h index 351c50c1..9b1ee98b 100644 --- a/QuickLook.Native/QuickLook.Native32/HelperMethods.h +++ b/QuickLook.Native/QuickLook.Native32/HelperMethods.h @@ -26,4 +26,6 @@ class HelperMethods private: static bool IsListaryToolbarVisible(); + static bool IsSearchBoxFocused(); + static HWND GetFocusedControl(); };