Skip to content

Commit

Permalink
Fix #579: search box changed in Windows 10 1909
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed May 19, 2020
1 parent 021ff26 commit 29d8baa
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 1 addition & 1 deletion QuickLook.Common
48 changes: 45 additions & 3 deletions QuickLook.Native/QuickLook.Native32/HelperMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, &gti);

return gti.flags || gti.hwndCaret || IsSearchBoxFocused() || IsListaryToolbarVisible();
}

bool HelperMethods::IsUWP()
Expand All @@ -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;
}
2 changes: 2 additions & 0 deletions QuickLook.Native/QuickLook.Native32/HelperMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ class HelperMethods

private:
static bool IsListaryToolbarVisible();
static bool IsSearchBoxFocused();
static HWND GetFocusedControl();
};

0 comments on commit 29d8baa

Please sign in to comment.