none
c++SDK怎么处理IWebBrowser2的新窗口弹出事件 RRS feed

  • 问题

  • c++SDK怎么处理IWebBrowser2的新窗口弹出事件,请把处理的主要流程和函数说下,谢谢,不用ATL
    2011年5月11日 2:07

答案

  • 你需要自己创建一个新的IE窗口并把结果传递给NewWindow2,参考http://support.microsoft.com/kb/184876



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年5月13日 15:39
    版主
  • 你需要自己创建一个新的IE窗口并把结果传递给NewWindow2,参考http://support.microsoft.com/kb/184876



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    解决了,谢谢。CWebBrowser2_NewWindow2( pDispParams->rgvarg[1].ppdispVal, pDispParams->rgvarg[0].pboolVal);,而且在newwindow里获取到正确的browserObject,就是和创建的时候一样的指针
    2011年5月14日 1:18

全部回复

  • 其实就是IDispatch这个接口的事情。这个接口C++里怎么实现

    2011年5月12日 0:39
  • 不是IDispatch,是IConnectionPointContainer,需要捕获的是DWebBrowserEvents2,具体代码参考ATL。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年5月12日 2:05
    版主
  • 不是IDispatch,是IConnectionPointContainer,需要捕获的是DWebBrowserEvents2,具体代码参考ATL。

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


    问题是这样的:能到Invoke这个里面,说明监听上了。。可是里面DISPID_NEWWINDOW和DISPID_BEFORENAVIGATE:这个没有触发

    /* [local] */ HRESULT STDMETHODCALLTYPE CWBClientSite::Invoke(
        /* [in] */ DISPID dispIdMember,
        /* [in] */ REFIID riid,
        /* [in] */ LCID lcid,
        /* [in] */ WORD wFlags,
        /* [out][in] */ DISPPARAMS *pDispParams,
        /* [out] */ VARIANT *pVarResult,
        /* [out] */ EXCEPINFO *pExcepInfo,
        /* [out] */ UINT *puArgErr)
    {
     switch(dispIdMember)
     {
     case DISPID_NEWWINDOW:
      CWebBrowser2_NewWindow2(pDispParams->rgvarg[2].punkVal, &pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pboolVal);
      break;
     case DISPID_BEFORENAVIGATE:
      CWebBrowser2_NewWindow2(pDispParams->rgvarg[2].punkVal, &pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pboolVal);
      break;
     default:
     break;
     }

     return(S_OK);
    }

    2011年5月12日 11:05
  • DISPID_NEWWINDOW

    你应该捕获newwindow2或者newwindow3

    DISPID_BEFORENAVIGATE

    这个应该在挂到新的窗口的BHO里面处理



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年5月12日 14:20
    版主
  • DISPID_NEWWINDOW

    你应该捕获newwindow2或者newwindow3

    DISPID_BEFORENAVIGATE

    这个应该在挂到新的窗口的BHO里面处理



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


    恩,现在是这么处理的:

    case DISPID_NEWWINDOW2:
      CWebBrowser2_NewWindow2(pDispParams->rgvarg[2].punkVal, &pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pboolVal);
      break;

    可以触发CWebBrowser2_NewWindow2这个函数,但是打开的时候还是在360浏览器上打开的,我想弹出一个新网页是拿我浏览器打开的

    void CWBClientSite:: CWebBrowser2_NewWindow2(IUnknown* EventSin, IDispatch** ppDisp, VARIANT_BOOL* pbCancel)
    {
     IWebBrowser2 *pBrowserApp;
     HRESULT hr  = -1;
     LPDISPATCH DbgppDisp = NULL;
     IOleObject  *browserObject;
     hr = m_pBrowserObj->QueryInterface(IID_IWebBrowser2, (void**)&pBrowserApp);
     if ( SUCCEEDED(hr) )
     { 
      *pbCancel = VARIANT_FALSE;
      hr = pBrowserApp->get_Application(&DbgppDisp);
      if ( SUCCEEDED(hr) )
      {
       *ppDisp  = DbgppDisp;
      } 
     }

    }

    2011年5月13日 1:27
  • DISPID_NEWWINDOW

    你应该捕获newwindow2或者newwindow3

    DISPID_BEFORENAVIGATE

    这个应该在挂到新的窗口的BHO里面处理



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    不是不是要自己先创建一个窗口,而且里面有webbrowser控件,在获取该控件的IOleObject。。。。
    2011年5月13日 1:52
  • 360浏览器改掉了注册表中的CLSID_InternetExplorer了,所以你要用自己的浏览器就要自己开浏览器进程,吧pbCancel设为TRUE.
    2011年5月13日 3:28
  • 360浏览器改掉了注册表中的CLSID_InternetExplorer了,所以你要用自己的浏览器就要自己开浏览器进程,吧pbCancel设为TRUE.

    恩,问题是把pbCancel设为TRUE.后,不会弹出来了。。。点击都没用了
    2011年5月13日 4:01
  • 要开新的窗口的话需要创建新的IE实例,直接把旧的传给NewWindow2的ppdosp不会有效果的

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年5月13日 5:02
    版主
  • 要开新的窗口的话需要创建新的IE实例,直接把旧的传给NewWindow2的ppdosp不会有效果的

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP


    那应该怎么办?我现在是直接传过去,,没效果

    void CWBClientSite:: CWebBrowser2_NewWindow2( IDispatch* ppDisp, VARIANT_BOOL* pbCancel)
    {
     
     MSG    msg;
     LPDISPATCH result = NULL;
     IWebBrowser2 *pBrowserApp;
     IOleObject  *browserObject;
     WNDCLASSEX wc = {0};
     HRESULT hr  = -1;
     LPDISPATCH DbgppDisp = NULL;

     *pbCancel=FALSE;
     
     SendMessageW(
      m_hWindow,
      WM_NEW_IEVIEW,
      (WPARAM)&(msg.hwnd),
      0);
     CWebBrowser *pWebBrowser = (CWebBrowser *)GetWindowLong(m_hWindow, GWL_USERDATA);
     browserObject = pWebBrowser->GetIOleObject();
     //browserObject = *((IOleObject **)GetWindowLong(m_hWindow, GWL_USERDATA));
     hr = browserObject->QueryInterface(IID_IWebBrowser2, (void**)&pBrowserApp);
     if ( SUCCEEDED(hr) )
     { 
      *pbCancel = VARIANT_TRUE;
      pBrowserApp->put_RegisterAsBrowser(*pbCancel);
      hr = pBrowserApp->get_Application(&DbgppDisp);
      
      if ( SUCCEEDED(hr) )
      {
       ppDisp  = DbgppDisp;
      } 
     }

    }

    2011年5月13日 7:01
  • 要开新的窗口的话需要创建新的IE实例,直接把旧的传给NewWindow2的ppdosp不会有效果的

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    帮忙看下这个函数直接调用CWebBrowser2_NewWindow2有没有问题,参数传递是否存在问题
    /* [local] */ HRESULT STDMETHODCALLTYPE CWBClientSite::Invoke(
        /* [in] */ DISPID dispIdMember,
        /* [in] */ REFIID riid,
        /* [in] */ LCID lcid,
        /* [in] */ WORD wFlags,
        /* [out][in] */ DISPPARAMS *pDispParams,
        /* [out] */ VARIANT *pVarResult,
        /* [out] */ EXCEPINFO *pExcepInfo,
        /* [out] */ UINT *puArgErr)
    {
     switch(dispIdMember)
     {
     case DISPID_NEWWINDOW2:
      CWebBrowser2_NewWindow2( pDispParams->rgvarg[1].pdispVal, pDispParams->rgvarg[0].pboolVal);
      break;
     case DISPID_BEFORENAVIGATE2:
       break;
     default:
     break;
     }

     return(S_OK);
    }

    2011年5月13日 8:13
  • 你需要自己创建一个新的IE窗口并把结果传递给NewWindow2,参考http://support.microsoft.com/kb/184876



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2011年5月13日 15:39
    版主
  • 你需要自己创建一个新的IE窗口并把结果传递给NewWindow2,参考http://support.microsoft.com/kb/184876



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP

    解决了,谢谢。CWebBrowser2_NewWindow2( pDispParams->rgvarg[1].ppdispVal, pDispParams->rgvarg[0].pboolVal);,而且在newwindow里获取到正确的browserObject,就是和创建的时候一样的指针
    2011年5月14日 1:18