Skip to content

Commit

Permalink
Fix #579: also deal with non-English UIs
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed May 20, 2020
1 parent 3f587c7 commit 5a02558
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
20 changes: 3 additions & 17 deletions QuickLook.Native/QuickLook.Native32/HelperMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,29 +90,15 @@ bool HelperMethods::IsListaryToolbarVisible()

// 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()
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();

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;
return wcscmp(classBuffer, L"Windows.UI.Core.CoreWindow") == 0;
}

bool HelperMethods::IsCursorActivated(HWND hwnd)
Expand All @@ -122,7 +108,7 @@ bool HelperMethods::IsCursorActivated(HWND hwnd)
GUITHREADINFO gti = { sizeof gti };
GetGUIThreadInfo(tId, &gti);

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

bool HelperMethods::IsUWP()
Expand Down
2 changes: 1 addition & 1 deletion QuickLook.Native/QuickLook.Native32/HelperMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class HelperMethods
static void GetSelectedInternal(CComQIPtr<IWebBrowserApp> pWebBrowserApp, PWCHAR buffer);
static void ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer);
static bool IsCursorActivated(HWND hwndfg);
static bool IsExplorerSearchBoxFocused();
static bool HelperMethods::IsUWP();

private:
static bool IsListaryToolbarVisible();
static bool IsSearchBoxFocused();
static HWND GetFocusedControl();
};
12 changes: 9 additions & 3 deletions QuickLook.Native/QuickLook.Native32/Shell32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
if (HelperMethods::IsCursorActivated(hwndfg))
return INVALID;

WCHAR classBuffer[MAX_PATH] = {'\0'};
WCHAR classBuffer[MAX_PATH] = { '\0' };
if (FAILED(GetClassName(hwndfg, classBuffer, MAX_PATH)))
return INVALID;

Expand All @@ -53,13 +53,19 @@ Shell32::FocusedWindowType Shell32::GetFocusedWindowType()
}
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 (FindWindowEx(hwndfg, nullptr, L"DUIViewWndClassName", nullptr) != nullptr)
{
return DIALOG;
if (!HelperMethods::IsExplorerSearchBoxFocused())
{
return DIALOG;
}
}
}

Expand Down

0 comments on commit 5a02558

Please sign in to comment.