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

  1. // CMy5View message handlers 
  2. #include <atlbase.h> 
  3. #include <Mshtml.h> 
  4. #include <COMDEF.H> 
  5. void CMy5View::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)  
  6.     // TODO: Add your specialized code here and/or call the base class 
  7.     CComPtr<IHTMLDocument2> pHTMLDocument2; 
  8.      
  9.     m_pBrowserApp->get_Document((IDispatch **)&pHTMLDocument2); 
  10.     if (pHTMLDocument2!=NULL) 
  11.     { 
  12.         CComPtr<IHTMLElement> pIHTMLElement; 
  13.         pHTMLDocument2->get_activeElement(&pIHTMLElement); 
  14.          
  15.         if (pIHTMLElement!=NULL) 
  16.         { 
  17.             variant_t url; 
  18.             HRESULT hr=pIHTMLElement->getAttribute(L"href", 0, &url); 
  19.             if (SUCCEEDED(hr)) 
  20.             { 
  21.                 hr=m_pBrowserApp->Navigate2(&url, NULL, NULL, NULL, NULL); 
  22.                  
  23.                 url.Clear(); 
  24.                  
  25.                 if (SUCCEEDED(hr)) 
  26.                 { 
  27.                     *Cancel=TRUE; 
  28.                 } 
  29.             } 
  30.         } 
  31. }    
  32. //  CHtmlView::OnNewWindow2(ppDisp, Cancel); 

猜你喜欢

转载自blog.csdn.net/yaowang107/article/details/79363163
今日推荐