现在可以通过AccessibleObjectFromWindow获取IAccessible接口,
然后使用枚举控件的方式,获取用户输入的网址。同样一段代码,
在MFC对话框环境下没有问题,但是在Windows Service服务程序中,
AccessibleObjectFromWindow函数总是返回失败,获取不到IAccessible接口,听说可以通过"会话"方式,"很容易"地获取火狐浏览器中输入的URL,
用DELPHI只要几行代码就可以搞定.但是因为没有思路,不知道如何建立会话,
通过Session,Cookie,或者跟火狐浏览器进程通信,或向火狐浏览器服务模拟发包,
是否可以获取到用户输入的URL呢?请熟悉的朋友帮忙介绍下,谢谢

解决方案 »

  1.   

    //通过枚举方式获取火狐浏览器中网址的关键代码 //枚举的方式获取火狐浏览器主窗体的句柄
    if(S_OK == (hr = AccessibleObjectFromWindow(hFireFoxMainWindow,OBJID_CLIENT, IID_IAccessible,(void**)&paccMainWindow)))
    {
    Find (
    paccMainWindow, 
    "搜索书签和历史",  //Name属性
    "可编辑文字",      //Role属性    
    "MozillaWindowClass", //Class属性
    &paccControl,
    &varControl,
    getFFURL);             
    }//=======================================================
    //枚举查找子控件,返回火狐浏览器中输入的网址
    BOOL Find (
       IAccessible* paccParent, 
       LPSTR szName,
       LPSTR szRole,
       LPSTR szClass,
       IAccessible** paccChild,
       VARIANT* pvarChild,
       CString &retURLValue)
    {
    HRESULT hr;         //返回结果
    long numChildren;   //子控件的数量
    IEnumVARIANT* pEnum = NULL; //枚举接口
    int indexCount;             //编历子控件的索引
    BOOL found = false;         //标记是否找到需要的子控件
    IAccessible* pCAcc = NULL;  //子控件接口指针

    unsigned long numFetched;
    VARIANT varChild;
    IDispatch* pDisp = NULL;

    CString strName;
    CString strValue;

    char szObjName[MAX_PATH], szObjRole[MAX_PATH], szObjClass[MAX_PATH], szObjState[MAX_PATH];

    //给枚举接口赋值
    hr = paccParent->QueryInterface(IID_IEnumVARIANT, (PVOID*) & pEnum);

    if(pEnum)
    pEnum -> Reset(); //将枚举序列重置到开始处

    //获取子控件的数量
    paccParent->get_accChildCount(&numChildren);

    for(indexCount = 1; indexCount <= numChildren && !found; indexCount++)
    {
    pCAcc = NULL;

    // Get next child
    if (pEnum)
    //检索枚举序列中指定数目的项
    hr = pEnum -> Next(1, &varChild, &numFetched);  
    else
    {
    varChild.vt = VT_I4;
    varChild.lVal = indexCount;
    }

    // Get IDispatch interface for the child
    if (varChild.vt == VT_I4)
    {
    pDisp = NULL;
    hr =paccParent->get_accChild(varChild, &pDisp);
    }
    else
    pDisp = varChild.pdispVal;

    // Get IAccessible interface for the child
    if (pDisp)
    {
    hr = pDisp->QueryInterface(IID_IAccessible, (void**)&pCAcc);

    hr = pDisp->Release();
    }

    // Get information about the child
    if(pCAcc)
    {
    VariantInit(&varChild);
    varChild.vt = VT_I4;
    varChild.lVal = CHILDID_SELF; 
    *paccChild = pCAcc;
    }
    else
    *paccChild = paccParent;

    //根据这个子控件接口获取子控件的相关属性
    BSTR bstrName;
    HRESULT hRet = (*paccChild)->get_accName(varChild, &bstrName); 
    SysFreeString(bstrName);

            if (bstrName != NULL)
    {
    //获取控件的Name属性
    strName= bstrName;
    strName.TrimLeft();
    strName.TrimRight();

    //获取控件的Value属性
    if (strName == "搜索书签和历史")
    {
    //获取Value值
    BSTR bstrValue;
    (*paccChild)->get_accValue(varChild, &bstrValue); 

    if (bstrValue != NULL)
    {
    strValue = bstrValue;
    strValue.TrimLeft();
    strValue.TrimRight();

    if (strValue != "搜索书签和历史")
    {
    //搜索到需要的网址
    retURLValue = strValue;
    found = TRUE; //找到需要的子控件
                            //AfxMessageBox(strValue);
    return TRUE; //返回
    }
    }
    }
    }

    if (!SUCCEEDED(hRet))
    {
    return FALSE; 
    //AfxMessageBox("获取子控件Name值失败");
    }

    if(!found && pCAcc) //递归遍历
    {    
    found = Find(pCAcc, szName, szRole, szClass, paccChild, pvarChild,retURLValue);

    if(*paccChild != pCAcc)
    pCAcc->Release();
    }
    } //End of For

    if(pEnum) //退出循环并释放资源
    pEnum -> Release();

    return found;
    }
      

  2.   

    https://developer.mozilla.org/en-US/
      

  3.   

    这个文件中临时存储访问的WEB网页信息
    但是要等浏览器关闭后,才向里面写东西/C:\Documents and Settings\Administrator\Application Data\Mozilla\Firefox\Profiles\cmxhzien.default\ntab\session.json参考的资料链接:
    关于cookie以及收藏夹
    http://blog.csdn.net/harrison2010/archive/2009/12/09/4974885.aspxMozilla Firefox中文社区论坛首页  
    http://www.firefox.net.cn/forum/viewforum.php?f=4&topicdays=0&start=50火狐社区
    http://17huohu.cn/qa/dev/?page=2