Fix #579: search box changed in Windows 10 1909

This commit is contained in:
Paddy Xu
2020-05-19 19:14:37 +03:00
parent 021ff268f6
commit 3f587c7b79
2 changed files with 47 additions and 3 deletions

View File

@@ -88,13 +88,41 @@ bool HelperMethods::IsListaryToolbarVisible()
return found; 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) bool HelperMethods::IsCursorActivated(HWND hwnd)
{ {
auto tId = GetWindowThreadProcessId(hwnd, nullptr); auto tId = GetWindowThreadProcessId(hwnd, nullptr);
GUITHREADINFO gui = {sizeof gui}; GUITHREADINFO gti = { sizeof gti };
GetGUIThreadInfo(tId, &gui); GetGUIThreadInfo(tId, &gti);
return gui.flags || gui.hwndCaret || IsListaryToolbarVisible();
return gti.flags || gti.hwndCaret || IsSearchBoxFocused() || IsListaryToolbarVisible();
} }
bool HelperMethods::IsUWP() bool HelperMethods::IsUWP()
@@ -108,3 +136,17 @@ bool HelperMethods::IsUWP()
UINT32 pn = 0; UINT32 pn = 0;
return pGCPFN(&pn, nullptr) == ERROR_INSUFFICIENT_BUFFER; 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;
}

View File

@@ -26,4 +26,6 @@ public:
private: private:
static bool IsListaryToolbarVisible(); static bool IsListaryToolbarVisible();
static bool IsSearchBoxFocused();
static HWND GetFocusedControl();
}; };