beforeNavigate2中如何实现?newwindow2中我用:
m_web.SetRegisterAsBrowser(1);
*ppDisp=m_web.GetApplication();
         *Cancel=TRUE;
点击连接的时候,却没反映?

解决方案 »

  1.   

    void CMyDlg2::OnNewWindow2Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel) 
    {
    m_web2.SetRegisterAsBrowser(1);
    *ppDisp=m_web2.GetApplication();
             *Cancel=TRUE;
    }
    //点击连接的时候为什么没有反映呀?是不是需要在OnBeforeNavigate2中设置什么?
      

  2.   

    OnNewWindow2中加入下面的代码 适合SDI和MDI
    CWinApp* pApp = AfxGetApp(); // Get the correct document template
    CDocTemplate* pDocTemplate;
    POSITION pos = pApp->GetFirstDocTemplatePosition();
    pDocTemplate = pApp->GetNextDocTemplate(pos); ASSERT(pDocTemplate); // Create the new frame
    CMainFrame* pNewFrame = (CMainFrame*)pDocTemplate->CreateNewFrame(GetDocument(),(CMainFrame*)AfxGetMainWnd());
    ASSERT(pNewFrame); // Activate the frame and set its active view
    pDocTemplate->InitialUpdateFrame(pNewFrame, NULL); CMfcieView* pWBVw = (CMfcieView*)pNewFrame->GetActiveView();
    ASSERT(pWBVw); pWBVw->SetRegisterAsBrowser(TRUE); *ppDisp = pWBVw->GetApplication();如果还不清楚,请参考微软MSDN  PSS ID Number: Q184876
      

  3.   

    刚才发的那个是让新打开的窗口都在你的程序中打开, 如果让新窗口都在原来的基础上打开你再参考一下MSDN PSS ID Number: Q294870
      

  4.   

    Controlling New Windows
    One important way to take control of the WebBrowser Control is to control navigation. You saw earlier how you can intercept DISPID_BEFORENAVIGATE2 in an IDispatch::Invoke implementation to control where your WebBrowser Control will navigate. Another important aspect of navigation is to control how the navigation occurs, especially when opening new windows. Let's say, for instance, that the user clicks the right mouse button over a link and chooses "Open in New Window" or that a page contains a script like this:window.open("www.msn.com");By default, the WebBrowser Control deals with this code by opening a new instance of Internet Explorer to display the page. This may be fine for your application. But then again, it may not. Perhaps you'll want all links to open in your current WebBrowser Control instance. Or perhaps you'll want to open a link in a new WebBrowser Control instance under your control, with your user interface and with your branding.You can intercept an event, DWebBrowserEvents2::NewWindow2, in your IDispatch implementation to control this. Your control needs to connect to the DWebBrowserEvents2 connection point to intercept this event.Once you're connected to DWebBrowserEvents2, implement your IDispatch::Invoke so that it handles DISPID_NEWWINDOW2. During the IDispatch::Invoke function call for DISPID_NEWWINDOW2, the array pDispParams contains two parameters. The first one, at index zero, is a Boolean value that tells the WebBrowser Control whether to cancel the new window or not. By default, it is FALSE and a new window will open. If you want to cancel new window creation completely, set the flag to TRUE.The parameter at index one is a pointer to an IDispatch interface. You can set this parameter to the IDispatch of a WebBrowser Control that you've created. When you pass back an IDispatch like this, MSHTML will use the control you've given it to open the link.