比如我有一个应用程序A,当程序A运行时,用户打开IE访问网页时,程序A可以获取用户正在打开的网页地址。不能做成插件或注入程序。大家有什么思路,给点建议。

解决方案 »

  1.   

    监视,如果打开了ie,就给IE的地址栏注册一个wndproc,就可以了
      

  2.   


       或者做个键盘钩子挂进去,装个Timer,定时检查IE地址栏
    这不是好办法,不过也可以实现方法太多了~
      

  3.   

    IHTMLDocument2* GetDocInterface(HWND hWndChild)           
    {      
    IHTMLDocument2* pDoc2 = NULL;        CComPtr<IHTMLDocument> spDoc = NULL;
    LRESULT lRes; if(::SendMessageTimeout(hWndChild, WM_HTMLGETOBJECT, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes))
    {
    HRESULT hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, (void**)&spDoc);
    if(S_OK == hr)   
    {
    CComPtr<IDispatch> spDisp;
    hr = spDoc->get_Script(&spDisp);
    if (SUCCEEDED(hr))
    {
    CComQIPtr<IHTMLWindow2> spWin = spDisp;
    spWin->get_document(&pDoc2); 
    }       
    }       
    }
    return     pDoc2;       
    }BOOL   CALLBACK   EnumChildProc(HWND   hwnd,LPARAM   lParam)   
    {   
    TCHAR buf[100];    ::GetClassName(hwnd, (LPTSTR)&buf, 100);   
    if(_tcscmp(buf, _T("Internet Explorer_Server")) == 0)
    {
    printf("Find Chiled IES");
    IHTMLDocument2*   pdoc2 = GetDocInterface(hwnd);
    if(pdoc2)   
    {   
    BSTR   bsturl;   
    pdoc2->get_URL(&bsturl);
    pdoc2->Release();
    _bstr_t bstrUrl(bsturl);

    DWORD pid = 0;
    GetWindowThreadProcessId(hwnd, &pid);
    printf("find[%d] IE window:%08X,url:%s\n",pid, (DWORD)hwnd, (char*)bstrUrl);

    SysFreeString(bsturl);
    //return FALSE;
    }
    }    return   TRUE;
    };           
    int main() 
    {
    HWND hwnd = ie的窗体;
    ::EnumChildWindows(hwnd, EnumChildProc, 0);
    }