您的位置:首页 > 其它

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

2016-03-10 20:37 489 查看
// 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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OnNewWindow2