您的位置:首页 > 其它

正确的方法去拦截OnNewWindow2实现在同一个窗口显示_target的网页

2012-07-16 21:51 591 查看
[cpp]
view plaincopyprint?

// CMy5View message handlers

#include <atlbase.h>
#include <Mshtml.h>

#include <COMDEF.H>
void CMy5View::OnNewWindow2(LPDISPATCH* ppDisp,
BOOL* Cancel)
{
// TODO: Add your specialized code here and/or call the base class

CComPtr<IHTMLDocument2> pHTMLDocument2;

m_pBrowserApp->get_Document((IDispatch **)&pHTMLDocument2);

if (pHTMLDocument2!=NULL)

{
CComPtr<IHTMLElement> pIHTMLElement;
pHTMLDocument2->get_activeElement(&pIHTMLElement);

if (pIHTMLElement!=NULL)

{
variant_t url;
HRESULT hr=pIHTMLElement->getAttribute(L"href", 0, &url);

if (SUCCEEDED(hr))

{
hr=m_pBrowserApp->Navigate2(&url, NULL, NULL, NULL, NULL);

url.Clear();

if (SUCCEEDED(hr))

{
*Cancel=TRUE;
}
}
}
}
// CHtmlView::OnNewWindow2(ppDisp, Cancel);

}

// CMy5View message handlers
#include <atlbase.h>
#include <Mshtml.h>
#include <COMDEF.H>
void CMy5View::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
{
// TODO: Add your specialized code here and/or call the base class
CComPtr<IHTMLDocument2> pHTMLDocument2;

m_pBrowserApp->get_Document((IDispatch **)&pHTMLDocument2);
if (pHTMLDocument2!=NULL)
{
CComPtr<IHTMLElement> pIHTMLElement;
pHTMLDocument2->get_activeElement(&pIHTMLElement);

if (pIHTMLElement!=NULL)
{
variant_t url;
HRESULT hr=pIHTMLElement->getAttribute(L"href", 0, &url);
if (SUCCEEDED(hr))
{
hr=m_pBrowserApp->Navigate2(&url, NULL, NULL, NULL, NULL);

url.Clear();

if (SUCCEEDED(hr))
{
*Cancel=TRUE;
}
}
}
}
//	CHtmlView::OnNewWindow2(ppDisp, Cancel);
}


找了一天了 整整找了4个半小时啊 终于被我找到解决方法了

就是VC6就可以解决了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐