Fix #579: also deal with non-English UIs

This commit is contained in:
Paddy Xu
2020-05-20 12:43:39 +03:00
parent 3f587c7b79
commit 5a02558ebe
3 changed files with 13 additions and 21 deletions

View File

@@ -90,29 +90,15 @@ bool HelperMethods::IsListaryToolbarVisible()
// Windows 10 1909 replaced the search box in the File Explorer by a UWP control. // Windows 10 1909 replaced the search box in the File Explorer by a UWP control.
// gti.flags is always 0 for UWP applications. // gti.flags is always 0 for UWP applications.
bool HelperMethods::IsSearchBoxFocused() bool HelperMethods::IsExplorerSearchBoxFocused()
{ {
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(); auto* hwnd = GetFocusedControl();
WCHAR classBuffer[MAX_PATH] = { '\0' }; WCHAR classBuffer[MAX_PATH] = { '\0' };
if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH))) if (FAILED(GetClassName(hwnd, classBuffer, MAX_PATH)))
return false; return false;
if (wcscmp(classBuffer, L"Windows.UI.Core.CoreWindow") != 0) return 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)
@@ -122,7 +108,7 @@ bool HelperMethods::IsCursorActivated(HWND hwnd)
GUITHREADINFO gti = { sizeof gti }; GUITHREADINFO gti = { sizeof gti };
GetGUIThreadInfo(tId, &gti); GetGUIThreadInfo(tId, &gti);
return gti.flags || gti.hwndCaret || IsSearchBoxFocused() || IsListaryToolbarVisible(); return gti.flags || gti.hwndCaret || IsListaryToolbarVisible();
} }
bool HelperMethods::IsUWP() bool HelperMethods::IsUWP()

View File

@@ -22,10 +22,10 @@ public:
static void GetSelectedInternal(CComQIPtr<IWebBrowserApp> pWebBrowserApp, PWCHAR buffer); static void GetSelectedInternal(CComQIPtr<IWebBrowserApp> pWebBrowserApp, PWCHAR buffer);
static void ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer); static void ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer);
static bool IsCursorActivated(HWND hwndfg); static bool IsCursorActivated(HWND hwndfg);
static bool IsExplorerSearchBoxFocused();
static bool HelperMethods::IsUWP(); static bool HelperMethods::IsUWP();
private: private:
static bool IsListaryToolbarVisible(); static bool IsListaryToolbarVisible();
static bool IsSearchBoxFocused();
static HWND GetFocusedControl(); static HWND GetFocusedControl();
}; };

View File

@@ -32,7 +32,7 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
if (HelperMethods::IsCursorActivated(hwndfg)) if (HelperMethods::IsCursorActivated(hwndfg))
return INVALID; return INVALID;
WCHAR classBuffer[MAX_PATH] = {'\0'}; WCHAR classBuffer[MAX_PATH] = { '\0' };
if (FAILED(GetClassName(hwndfg, classBuffer, MAX_PATH))) if (FAILED(GetClassName(hwndfg, classBuffer, MAX_PATH)))
return INVALID; return INVALID;
@@ -53,13 +53,19 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
} }
if (wcscmp(classBuffer, L"ExploreWClass") == 0 || wcscmp(classBuffer, L"CabinetWClass") == 0) if (wcscmp(classBuffer, L"ExploreWClass") == 0 || wcscmp(classBuffer, L"CabinetWClass") == 0)
{ {
return EXPLORER; if (!HelperMethods::IsExplorerSearchBoxFocused())
{
return EXPLORER;
}
} }
if (wcscmp(classBuffer, L"#32770") == 0) if (wcscmp(classBuffer, L"#32770") == 0)
{ {
if (FindWindowEx(hwndfg, nullptr, L"DUIViewWndClassName", nullptr) != nullptr) if (FindWindowEx(hwndfg, nullptr, L"DUIViewWndClassName", nullptr) != nullptr)
{ {
return DIALOG; if (!HelperMethods::IsExplorerSearchBoxFocused())
{
return DIALOG;
}
} }
} }