积极答复者
c++SDK怎么处理IWebBrowser2的新窗口弹出事件

问题
答案
-
你需要自己创建一个新的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- 已标记为答案 VisualElevenModerator 2011年5月15日 12:59
-
你需要自己创建一个新的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,就是和创建的时候一样的指针- 已标记为答案 VisualElevenModerator 2011年5月15日 12:59
全部回复
-
不是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 -
不是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);
} -
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 -
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;
}
}}
-
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。。。。 -
要开新的窗口的话需要创建新的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 -
要开新的窗口的话需要创建新的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;
}
}}
-
要开新的窗口的话需要创建新的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);
} -
你需要自己创建一个新的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- 已标记为答案 VisualElevenModerator 2011年5月15日 12:59
-
你需要自己创建一个新的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,就是和创建的时候一样的指针- 已标记为答案 VisualElevenModerator 2011年5月15日 12:59