最近在做个东西,实现用户单击“确定”按钮时,弹出“保存成功”对话框,捕获这个对话框中的文字“保存成功”,现在我调试获取DISPID_HTMLFORMELEMENTEVENTS_ONSUBMIT和DISPID_HTMLELEMENTEVENTS_ONCLICK可是这两种方法都不行?请高手指教??

解决方案 »

  1.   

    最好通过你网页的javascript来获得弹出的窗口上的信息等》。。..
    再通知你的BHO
      

  2.   

    最好不要用JavaScript,我截获了提交事件和单击按钮事件,可是这两种事件,提交事件是在单击对话框中的“确定”按钮后才进入提交事件中,而单击按钮事件,则是单击按钮后直接进入DISPID_HTMLELEMENTEVENTS_ONCLICK中,而对话框还没有显示,所以无法捕获对话框,请各位指点。
      

  3.   

    需要先分析对话框是用什么方式弹出来的,alert? confirm? showModelDialog? 拦截方式是不一样的。
      

  4.   

    替换IHTMLWindow2对象的alert方法,拦截参数后调用原始方法
      

  5.   

    看看这里 : http://topic.csdn.net/t/20041018/21/3468075.html
      

  6.   

    我给的 http://topic.csdn.net/t/20041018/21/3468075.html 里面就有这个方面,仔细看看~
      

  7.   

    我已经仔细看了,确实阻止弹出的alert对话框,但下一步,怎么捕获弹出对话框中的的句柄,并最终获取对话框中的内容呢?
      

  8.   

    我已经仔细看了,谢谢oyljerry ,这个是阻止弹出的alert对话框,我想解决的是怎么捕获弹出对话框中的的句柄,并最终获取对话框中的内容呢?
      

  9.   


    简单地插入下面代码在文档开头(OnDocumentComplete时)
    <script>
    var alert_api = window.alert;
    window.alert = function alert_new(msg){
    // 用一些办法像改变html某个元素文本,进行通告msg..
    }
    </script>
      

  10.   

    <script>
    var alert_api = window.alert;
    window.alert = function alert_new(msg){
    // 用一些办法像改变html某个元素文本,进行通告msg.. 
    ....
    // 调用原始window.alert,弹出message box..
    alert_api(msg);
    }
    alert('ok');
    </script>
      

  11.   

    谢谢,不能用script语句,因为要做个通用的东西,别人做好的网页或项目,怎么改script语句呢?我要的是IE弹出文本框就取出文本框中的文字,如alert(“成功”);让后将文本框中的文字“成功”,保存到数据库中进行后续的处理。
      

  12.   

    用脚本能做到的,VC一定也能够做到,只要把js代码翻译成C++代码即可。
      

  13.   

    何必一定非要通过alert呢
    完全可以通过其它方式
    说说最原始需求
    看了回帖,感觉楼主已经钻进牛角尖里去了
      

  14.   

    现在在做个BHO,当网页弹出对话框时,保存对话框中的文字,例如网页中有“确定”按钮,点击“确定”,弹出对话框“保存成成功”,将对话框中的文字保存到数据库中,进行下一步处理。
    目前难点是如何实时捕捉对话框弹出事件。
      

  15.   

    类似于在BHO中实现IDocHostUIHandler一样,在宿主类中实现IDocHostShowUI接口,重点实现IDocHostShowUI接口的ShowMessage()
    HRESULT ShowMessage(          HWND hwnd,
        LPOLESTR lpstrText,
        LPOLESTR lpstrCaption,
        DWORD dwType,
        LPOLESTR lpstrHelpFile,
        DWORD dwHelpContext,
        LRESULT *plResult
    );
    lpstrText中就是你想获得的弹出窗口内容,你在ShowMessage()函数中,想怎么玩就怎么玩
      

  16.   

    你可以通过IDocHostShowUI::ShowMessage()的返回值来控制不显示信息框、或者显示自己的信息框,或者显示mshtml的原装信息框。
    S_OK 不显示MSHTML的信息框,信息框由宿主在ShowMessage()函数中定制 
    S_FALSE 显示MSHTML的信息框 
      

  17.   


    HRESULT CBrowserHost::ShowMessage(HWND hwnd,
                                      LPOLESTR lpstrText,
                                      LPOLESTR lpstrCaption,
                                      DWORD dwType,
                                      LPOLESTR lpstrHelpFile,
                                      DWORD dwHelpContext,
                                      LRESULT *plResult) 
    {
        USES_CONVERSION;
        TCHAR pBuffer[50];    // resource identifier for window caption "Microsoft Internet Explorer"
        #define IDS_MESSAGE_BOX_TITLE    2213    // Load Shdoclc.dll and the IE message box title string
        HINSTANCE hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));

        if (hinstSHDOCLC == NULL)
        {
           //Error loading module -- fail as securely as possible
           return;
        }
     
        LoadString(hinstSHDOCLC, IDS_MESSAGE_BOX_TITLE, pBuffer, 50);    // Compare the IE message box title string with lpstrCaption
        // If they're the same, substitute your own Caption
        if (_tcscmp(OLE2T(lpstrCaption), pBuffer) == 0)
            lpstrCaption = L"New Caption";    // Create your own message box and display it
        *plResult = MessageBox(OLE2T(lpstrText), OLE2T(lpstrCaption), dwType);    // Unload Shdoclc.dll and return
        FreeLibrary(hinstSHDOCLC);
        return S_OK;
    }
      

  18.   

    IDocHostShowUI::ShowMessage()是自定义对话框样式,而不能捕获对话框弹出事件,现在问题是如何捕获对话框弹出事件?
    不过还是谢谢
      

  19.   

    HRESULT ShowMessage(          HWND hwnd,
        LPOLESTR lpstrText,
        LPOLESTR lpstrCaption,
        DWORD dwType,
        LPOLESTR lpstrHelpFile,
        DWORD dwHelpContext,
        LRESULT *plResult
    );
    lpstrText中难道不是你想获得的弹出窗口内容?
      

  20.   

    我估计楼主根本没有把包含IDocHostShowUI接口的宿主,通过mshtml的ICustomDoc接口的SetUIHandler()注入进去。
      

  21.   

    谢谢,我对方面不熟悉,前段时间一直在试图用bho拦截case DISPID_HTMLFORMELEMENTEVENTS_ONSUBMIT事件,截获弹出对话框事件。可能走弯路了!!!
      

  22.   


    以你有这方面的资料没,我现在ATL编写的bho,按照你说的我已经实现IDocHostShowUI::ShowMessage(),可是下一步不知道如何将其同BHO关联,IDocHostShowUI这方面我网上找了资料,搞不懂他同BHO的关系,能说下么,或者发些资料最好!!!!
      

  23.   

    不明白什么意思,怎么通过mshtml的ICustomDoc接口的SetUIHandler()注入进去。 有代码没?
      

  24.   

    比如按照http://msdn.microsoft.com/en-us/library/bb250489.aspx
    class ATL_NO_VTABLE CHelloWorldBHO :
        public CComObjectRootEx<CComSingleThreadModel>,
        public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>,
        public IObjectWithSiteImpl<CHelloWorldBHO>,
        public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
        public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>让CHelloWorldBHO这个类继承IDocHostShowUI接口。按照mshtml的架构,那么CHelloWorldBHO这个类就是宿主类。
    实现CHelloWorldBHO::ShowMessage()和CHelloWorldBHO::ShowHelp()这两个函数。
    在void STDMETHODCALLTYPE CHelloWorldBHO::OnDocumentComplete(IDispatch *pDisp, VARIANT *pvarURL)函数中的相应地方添加以下代码
      if   (m_spWebBrowser)   
      {   
              CComPtr<IDispatch>   spDoc;   
              m_spWebBrowser->get_Document(&spDoc);   
        
              if   (spDoc)   
              {   
                      CComQIPtr<ICustomDoc,   &IID_ICustomDoc>   spCustomDoc(spDoc);   
                      if   (spCustomDoc)   
                              spCustomDoc->SetUIHandler(this);   
              }   
      }   
    在CHelloWorldBHO::ShowMessage(HWND hwnd,
                                      LPOLESTR lpstrText,
                                      LPOLESTR lpstrCaption,
                                      DWORD dwType,
                                      LPOLESTR lpstrHelpFile,
                                      DWORD dwHelpContext,
                                      LRESULT *plResult)
    函数中,传入的参数lpstrText就是mshtml的弹出信息框的内容。
    这个很类似回调机制,不过mshtml是通过接口实现的。这个实现机理估计是这样:mshtml在弹出信息框前,会问:“宿主实现了IDocHostShowUI接口么?”而SetUIHandler告诉mshtml:“宿主是CHelloWorldBHO,它实现了IDocHostShowUI接口”,mshtml就会调用CHelloWorldBHO的ShowMessage(),并把要弹出的信息框内容以参数形式传进去,并根据ShowMessage()的返回值确定是否显示mshtml的缺省信息框。通过类似机理,宿主就可以控制mshtml的一切,当然也包括你想预先获得的弹出窗口的信息。
      

  25.   


    我怎么编译通过呀,atlcom.h(3699) : error C2039: '_GetSinkMap' : is not a member of 'CEyeOnIE'
      

  26.   

    我一加上public IDispEventImpl<1,CEyeOnIE, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>编译就不通过
    以下是错误提示:
    d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2039: '_GetSinkMap' : is not a member of 'CEyeOnIE'
            d:\lv\资料\test\eyeonie.h(17) : see declaration of 'CEyeOnIE'
            d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
    ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
    d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2065: '_GetSinkMap' : undeclared identifier
            d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
    ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
    d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2440: 'initializing' : cannot convert from 'int' to 'const struct ATL::_ATL_EVENT_ENTRY<class CEyeOnIE> *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
            d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
    ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
    EyeOnIE.cpp
    D:\lv\资料\test\EyeOnIE.cpp(181) : warning C4101: 'hwnd' : unreferenced local variable
    d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2039: '_GetSinkMap' : is not a member of 'CEyeOnIE'
            d:\lv\资料\test\eyeonie.h(17) : see declaration of 'CEyeOnIE'
            d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
    ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
    d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2065: '_GetSinkMap' : undeclared identifier
            d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
    ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
    d:\microsoft visual studio\vc98\atl\include\atlcom.h(3699) : error C2440: 'initializing' : cannot convert from 'int' to 'const struct ATL::_ATL_EVENT_ENTRY<class CEyeOnIE> *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
            d:\microsoft visual studio\vc98\atl\include\atlcom.h(3697) : while compiling class-template member function 'long __stdcall ATL::IDispEventSimpleImpl<1,class CEyeOnIE,&struct _GUID const DIID_DWebBrowserEvents2>::Invoke(long,const struct _GU
    ID &,unsigned long,unsigned short,struct tagDISPPARAMS *,struct tagVARIANT *,struct tagEXCEPINFO *,unsigned int *)'
    这是怎么回事呀???
      

  27.   

    按照http://msdn.microsoft.com/en-us/library/bb250489.aspx的说明,一步步来,别随便复制代码
    CEyeOnIE少定义了_GetSinkMap的相关宏
      

  28.   

    我用的是vc6.0,上面用的是vs2005,这应该不会出现错误。
      

  29.   

    你按照VC6的向导,做出和按照http://msdn.microsoft.com/en-us/library/bb250489.aspx同样效果的BHO,调试无误后,再添加IDocHostShowUI接口,写相关函数,应该不会有错误的
      

  30.   

    我严格按照http://msdn.microsoft.com/en-us/library/bb250489.aspx,用vs2005做了一遍,还是出现了同样的错误,
    错误 1 error C2039: '_GetSinkMap' : is not a member of 'CHelloWorldBHO'
    e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 4137 为何????
      

  31.   

    error C2039: '_GetSinkMap' : is not a member of 'CHelloWorldBHO' 
    e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 4137 ,问题已经解决.
      

  32.   

     我在添加IDocHostShowUI接口,写相关函数,总报错,
    class /*ATL_NO_VTABLE*/ CHelloWorldBHO :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>,
    public IObjectWithSiteImpl<CHelloWorldBHO>,
    public IDocHostUIHandler,
    public IDocHostShowUI,

    public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
    public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>
    错误为
    错误 1 error C2259: 'ATL::CComObject<Base>' : cannot instantiate abstract class e:\program files\microsoft visual studio 8\vc\atlmfc\include\atlcom.h 1792