Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3029

[RESOLVED] Get active url in Google Chrome from v.29 with IAccessible

$
0
0
Based in some examples of source codes as this => http://stackoverflow.com/questions/2...urrent-version, I'm trying get active url on address bar from Google Chrome with IAccessible, but it always return NULL (0). Could someone help me please?

Any suggestion will be welcome.

Here is my last attempt:

Code:


#include "stdafx.h"
#include <Windows.h>
#include <Oleacc.h>
#pragma comment( lib,"Oleacc.lib")

HWINEVENTHOOK LHook = 0;

void CALLBACK WinEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) {

    IAccessible* pAcc = NULL;
    VARIANT varChild;
    HRESULT hr = AccessibleObjectFromEvent(hwnd, idObject, idChild, &pAcc, &varChild);

    if ((hr == S_OK) && (pAcc != NULL)) {
        BSTR bstrValue;
        pAcc->get_accValue(varChild, &bstrValue);

        char className[500];
        GetClassName(hwnd, (LPWSTR)className, 500);

        if (event == EVENT_OBJECT_VALUECHANGE){

            /*

          Window classe name of each browser =>

            Safari => SafariTaskbarTabWindow
            Chrome => Chrome_WidgetWin_1
            IE => IEFrame
            Firefox => MozillaWindowClass
            Opera => OperaWindowClass

            */

            if (strcmp(className, "Chrome_WidgetWin_1") != 0) {
                printf("Active URL: %ls\n", bstrValue);
            }
        }
        SysFreeString(bstrValue);
        pAcc->Release();
    }
}

void Hook() {

    if (LHook != 0) return;
    CoInitialize(NULL);
    LHook = SetWinEventHook(EVENT_OBJECT_FOCUS, EVENT_OBJECT_VALUECHANGE, 0, WinEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
}

void Unhook() {

    if (LHook == 0) return;
    UnhookWinEvent(LHook);
    CoUninitialize();
}


int main(int argc, const char* argv[]) {

    MSG msg;
    Hook();

    while (GetMessage(&msg, NULL, 0, 0)) {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    Unhook();

    return 0;
}


Viewing all articles
Browse latest Browse all 3029

Latest Images

Trending Articles



Latest Images