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

来源:互联网 发布:程序员项目总结怎么写 编辑:程序博客网 时间:2024/04/30 01:56

// 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 classCComPtr<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就可以解决了




原创粉丝点击