1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
void BrowserMonitor::WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime)
{
static string found_url;
static vector<string> viewedUrls;
IAccessible* pAcc = NULL;
VARIANT varChild;
if ((AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild) == S_OK) &&
(pAcc != NULL))
{
char className[50];
if (GetClassName(hwnd, (LPWSTR)className, 50) && strcmp(className, "Chrome_WidgetWin_1") == 0)
{
BSTR bstrName = nullptr;
if (pAcc->get_accName(varChild, &bstrName) == S_OK)
{
if (wcscmp(bstrName, L"Address and search bar") == 0)
{
BSTR bstrValue = nullptr;
if (pAcc->get_accValue(varChild, &bstrValue) == S_OK)
{
wstring wstringValue(bstrValue);
std::string strValue;
if(found_url != strValue && find(viewedUrls.begin(), viewedUrls.end(),
strValue) == viewedUrls.end())
{
found_url = strValue;
}
viewedUrls.push_back(strValue);
SysFreeString(bstrValue);
}
}
SysFreeString(bstrName);
}
pAcc->Release();
}
}
}
void BrowserMonitor::hook()
{
qDebug() << chromeEdgeBraveAddressBarIdentifier;
if (LHook != 0) return;
CoInitialize(NULL);
LHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_VALUECHANGE, 0, WinEventProc, 0, 0, WINEVENT_SKIPOWNPROCESS); // error: reference to non-static member function must be called
}
|