当外部应用程序(例如Microsoft Edge,Firefox或Chrome)的焦点发生变化时,我正在使用Accessibility API来担任角色。在十月份更新Windows之前,以下代码一直有效。更新后,角色始终被报告为ROLE_SYSTEM_CLIENT
我做错什么了吗,或者这是更新中的错误吗?
HWINEVENTHOOK objectFocusHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_FOCUS, NULL, &CMonitor::WinEventHookProc, 0, 0, WINEVENT_OUTOFCONTEXT);
然后
void CALLBACK CMonitor::WinEventHookProc(HWINEVENTHOOK hook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD idEventThread, DWORD time)
{
if (event == EVENT_OBJECT_FOCUS)
{
IAccessible* pAcc = nullptr;
VARIANT varChild;
if (SUCCEEDED(AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild)))
{
BSTR bstrName;
VARIANT varRole;
VARIANT varState;
pAcc->get_accName(varChild, &bstrName);
// after October update this always return ROLE_SYSTEM_CLIENT
if (SUCCEEDED(pAcc->get_accRole(varChild, &varRole)))
{
if (varRole.lVal == ROLE_SYSTEM_TEXT)
{
if (SUCCEEDED(pAcc->get_accState(varChild, &varState)))
{
// we do more with this
bool isProtected = (varState.lVal & STATE_SYSTEM_PROTECTED) != 0;
}
}
}
pAcc->Release();
}
}
}