virtual void OnNewWindow2( LPDISPATCH* ppDisp, BOOL* Cancel );
将Cancel设为true不行吗?

解决方案 »

  1.   

    我用的是CWebBrowser2控件。 CWebBrowser2* wb = &this->m_WebBrowser2;
    wb->SetRegisterAsBrowser(TRUE);
    *ppDisp = wb->GetApplication();转移了一次指针,刷新不了。
      

  2.   

    不要试图改变ppDisp,它是用来执行命令的。
    可以试一下OnBeforeNavigate2,它可能是你所想要的。判断地址是否可访问,如要取消:*Cancel=true;可以看一下:Microsoft Knowledge Base HOWTO: Use the WebBrowser Control NewWindow2 Event
    (http://msdn.microsoft.com/isapi/gosupport.asp?TARGET=/support/kb/articles/q184/8/76.asp)多少给一点分吧,这将是我的第一桶金。
      

  3.   

    在msdn上有一些代码可以控制弹出窗口,
    不过它们都是把指针转给了新的控制窗口,
    我想在当前的窗口中获得这个指针的操作权。
    不知道有没有人会?
      

  4.   

    CWebBrowser2* wb = &this->m_WebBrowser2;
    *Cancel = TRUE;   //避免打开新窗口
    wb->SetSilent(TRUE); // else error from javascript
    SetTimer(3,1000,NULL); // just to re-enable Silent(FALSE);
    可是这样,什么也不打开了。还得获得即将打开的网页的URL
    然后再用wb去Navigate
      

  5.   

    楼上这位大哥,如果是打开一个要登录才能进入的页面,
    就不能用Navigate,一定要用那个指针.
      

  6.   

    这段代码你会不会吐血?其实不用C++,应该使用HTML中的方法:
    以下摘自CSDN的登陆HTML代码,用作举例:
    ---------------------
    <form method="POST" action="http://www.csdn.net/member/logon.asp" target="_blank" name="a"><!-- 其中target="foo"是控制窗口是否弹处出的关键,下面列出各值意义 -->    <td valign="bottom" bgcolor=#e0dedf width="340">
         昵称:<input type="text" name="name" size="10" class="from1">
         密码:<input type="password" name="pass" size="10" class="from1">
         <select size="1" name="type"> 
            <option value="1" selected>我的论坛</option>
            <option value="2">我的软件</option>
            <option value="3">我的订单</option>
            <option value="4">我的文档</option>
            <option value="5">我的简历</option>
          </select>
        </td>
        <td bgcolor=#e0dedf valign="bottom" width="45">
         <INPUT type=image src="http://www.csdn.net/images/denglu.gif" width="44" height="17">
        </td>
        <td bgcolor=#e0dedf valign="bottom" width="45">
         <a href="http://www.csdn.net/expert/zc.asp" target="_parent">
            <img src="http://www.csdn.net/images/zhuce.gif" border="0"></a>
        </td>
    </form>
    ----------------------
    target="foo"的值:
      target="_blank",在弹出新窗口,打开连接的HTML文档
      target="_self",在当前窗口打开连接的文档(可缺省)
      target="_parent",在有Frame结构的文档时,在frame's setting文档中打开连接的文档,不然同"_self"
      target="_top",在有Frame结构的文档时,撑满整个浏览器客户区,不然同"_self"丘丘说的使用ppDisp指针,它是指向COM的IDispatch自动化接口的,可用VB中的对象浏览器看一下它的属性,方法,事件(VB中为Microsoft Internet Control),其实应该全部都在CWebControl包装类中有对应包装。在VC使用IDispatch中的方法太复杂了,我基本不会(^_^),读Inside COM可能有帮助(我在读,没读懂)。如果是内部系统的话,HTML仔细写一下,在OnBeforeNavigate2中判断lpszURL是否超越你的网络,超越就Cancel掉,不知各位觉得这个方法好不好?我其实也是初学者(今年升大二),以上是我的全部家当了。丘丘不知满意否?
      

  7.   

    要是浏览的可能是Internet呢?
      

  8.   

    丁丁,我不满意。
    我要浏览的是internet.
    不是自己写的html页.
    如果实在不行,我就准备两个CWebBrowser2,
    打开一个弹出窗口,就销毁前一个窗口,把弹出窗口控制为当前窗口,
    在某个com接口中得到前进,后退的指针。
    看起来就像在当前窗口刷新一样了。
      

  9.   

    这是以前的一个回答(http://expert.csdn.net/TopicView.asp?id=855)
    我试了一下,好像也不行……,丘丘,这个问题好像比较难喔。
    再多积点分,问一下吧。--回复得分 110 --
    正好今天网速较快,我在msdn online查了一下,找到了,无需再下载新版internet sdk,不用处理OnBeforeNavigate2.文档如下:
    Using MFC, you may wish to do this in one of three types of applications: 
    Dialog-based
    Single document interface (SDI)
    Multiple document interface (MDI) 
    Here is some sample MFC code that would accomplish this task in a dialog- based application: 
       void CYourDlg::OnNewWindow2(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel)
       {
          m_dlgNewWB = new CYourDlg;
          m_dlgNewWB->Create(IDD_WBDLG_DIALOG);      *ppDisp = m_dlgNewWB->m_webBrowser.GetApplication();
       } 
    Here is some sample MFC code that would accomplish this task in an SDI or MDI application. This code creates a new frame that contains a WebBrowser control. In an SDI application, this frame would appear to the user to look like another instance of the application. In an MDI application, this frame is the same as if the user had chosen to open a new child window. 
     void CYourView::OnNewWindow2(LPDISPATCH FAR* ppDisp,
                                  BOOL FAR* Cancel)
     {
        // Get a pointer to the application object
        CWinApp* pApp = AfxGetApp();    // Get the correct document template
        CDocTemplate* pDocTemplate;
        POSITION pos = pApp->GetFirstDocTemplatePosition();
        pDocTemplate = pApp->GetNextDocTemplate(pos);    ASSERT(pDocTemplate);    // Create the new frame
        CFrameWnd* pNewFrame = pDocTemplate->CreateNewFrame(GetDocument(),
                                       (CFrameWnd*)AfxGetMainWnd());
        ASSERT(pNewFrame);    // Activate the frame and set its active view
        pDocTemplate->InitialUpdateFrame(pNewFrame, NULL);    CYourView* pWBVw = (CYourView*)pNewFrame->GetActiveView();
        ASSERT(pWBVw);    *ppDisp = pWBVw->m_webBrowser.GetApplication();
     } 
      

  10.   

    唉,这个回复分明就是抄的msdn.
    兄弟们加油啊