昨天这样嵌入页面可以了,CTestbrowserDlg* m_dlgNewWB =  new CTestbrowserDlg;  
m_dlgNewWB->Create(IDD_TESTBROWSER_DIALOG);  
*ppDisp =  m_dlgNewWB->m_ctrlWeb.GetApplication();  
可是还有点问题。
1. 网页的位置不在窗体的0,0,点,怎么设置好呢。
2. 关闭二级页面后就不能再打开了,怀疑是哪里没有释放掉什么,怎么释放它呢?谢谢啦,非常着急

解决方案 »

  1.   

    1、是浏览器控件的位置不对吗?可以在初始化时用MoveWindow设置控件位置和大小。
    2、每次用new构造对话框对象,对话框响应WM_CLOSE消息,调用DestroyWindow销毁窗口,再重载PostNcDestroy函数delete this销毁对象。
      

  2.   

    1.我这样做的,加载OnInitDialog()或者OnCreate()下都没有变化:
    RECT rect;
    GetClientRect(&rect);
    rect.left=0;
    rect.top=0;
    m_explorer.MoveWindow(&rect);
    2我再试试看。
      

  3.   

    在OnInitDialog中处理,要先执行基类的OnInitDialog函数。
      

  4.   

    可以在对话框析构等中,delete this; 来释放...
      

  5.   

    谢谢啦,问题二解决了,就是需要closewindow.问题1怎么解决呢?我现在这样的
    CDialog::OnInitDialog();

    CenterWindow(CWnd::FromHandle(m_hWnd)); RECT rect;
    //m_explorer.GetClientRect(&rect);
    GetClientRect(&rect);
    rect.left-=100;
    rect.right-=100;
    rect.top-=100;
    rect.bottom-=100;
    m_explorer.MoveWindow(&rect); return TRUE; 我发现一个很奇怪的问题,m_explorer开始在我所设置的位置,闪了一下,就又到右下角去了。这个怎么解决呢?
      

  6.   

    关于问题2,我现在是2个对话框,第一个对话框打开二级页面时候调用第二个对话框,我现在这样做:
    void CDlg2::OnClose() 
    {
    // TODO: Add your message handler code here and/or call default
    m_explorer.CloseWindow();
    m_explorer.DestroyWindow(); CDialog::OnClose();
    }
    然后
    void CDlg::OnNewWindow2Explorer1(LPDISPATCH FAR* ppDisp, BOOL FAR* Cancel) 
    {
    //  AfxMessageBox("new window");
      if(m_dlgNewWB)
    {
    m_dlgNewWB->CloseWindow();
    delete m_dlgNewWB;
    m_dlgNewWB = NULL;
    }
      m_dlgNewWB = new CDlg2();
      m_dlgNewWB->Create(IDD_ALARMSTAT_DLG2);
      m_dlgNewWB->SetOwner(this);
      m_dlgNewWB->ShowWindow(SW_SHOW);
      BringWindowToTop();
      m_dlgNewWB->m_explorer.SetRegisterAsBrowser(TRUE);
      *ppDisp = m_dlgNewWB->m_explorer.GetApplication();
    }
    这样没有问题了,有更好的解决方法吗?这样就是在CDlg的开始要设置m_dlgNewWB=NULL;
      

  7.   

    void CDlg2::OnClose()
    {
    // TODO: Add your message handler code here and/or call default
    m_explorer.CloseWindow();
    m_explorer.DestroyWindow();delete this;  // 不过你要保证CDlg2都是new的
    CDialog::OnClose();
      

  8.   

    问题1怎么解决呢?我现在这样的 
    CDialog::OnInitDialog(); CenterWindow(CWnd::FromHandle(m_hWnd)); RECT rect; 
    //m_explorer.GetClientRect(&rect); 
    GetClientRect(&rect); 
    rect.left-=100; 
    rect.right-=100; 
    rect.top-=100; 
    rect.bottom-=100; 
    m_explorer.MoveWindow(&rect); return TRUE; 我发现一个很奇怪的问题,m_explorer开始在我所设置的位置,闪了一下,就又到右下角去了。这个怎么解决呢?
    谢谢各位,解决问题马上结贴
      

  9.   

    CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pHtmlDoc2 = (IHTMLDocument2*)m_ie.GetDocument();
     if(pHtmlDoc2==NULL)return;
      CComPtr<IHTMLElement> pBodyElement;
      if(pHtmlDoc2->get_body( &pBodyElement)!=S_OK||pBodyElement==NULL)return;CComPtr<IHTMLBodyElement> phtmlbody;  
    pBodyElement->QueryInterface(&phtmlbody);  
    if  (phtmlbody!=NULL)  
    {  
    phtmlbody->put_leftMargin(CComVariant(/*x*/0)); //左边距
    phtmlbody->put_topMargin(CComVariant(/*x*/0));//上边距
    }
      

  10.   

    CTan2 *dlg1=new CTan2(this);
    dlg1->Create(IDD_DIALOG2);
    dlg1->CenterWindow();
    dlg1->ShowWindow(SW_SHOW);
    *ppDisp =dlg1->m_ie.GetApplication();
      

  11.   

    CTan2里面:void CTan2::OnClose() 
    {
    DestroyWindow();
    //CDialog::OnClose();
    }
    //**********************************void CTan2::PostNcDestroy() 
    {
    // TODO: Add your specialized code here and/or call the base class
    delete this;
    //CDialog::PostNcDestroy();
    }//*************************************关闭时用CWnd::PostMessage(WM_CLOSE,0,0);
      

  12.   

    我在onButton1()里面做了那个代码,有效果,可是就向左上移动了一点,基本上在中间的位置,根本不是0,0,我把参数设置为-100,直接没有变化了。它为社么会认为中间是0点呢?
      

  13.   

    问题解决了,SetWindowPos要在OnDownloadComplete里面才行。
      

  14.   

    m_ie.SetTop(x);//CWebbrowser2 m_ie;
    m_ie.SetLeft(x);
    //*****************************上面两个可调整窗口位置放哪都行//**************下面两个调整窗口里的内容,须该html下载完毕时phtmlbody->put_leftMargin(CComVariant(/*x*/0)); //左边距 
    phtmlbody->put_topMargin(CComVariant(/*x*/0));//上边距 //**************************
    CTan2 *dlg1=new CTan2(this); 中的dlg1是函数里面随时声明的变量(不是在类.h),这样多次弹出时可减少‘错误’发生。你要注意,我回复帖子,不一定是给原发帖者看的!