这种情况不容易处理,实在不行你就把你的程序改成SDI的,然后ChildFrm从CFormView派生

解决方案 »

  1.   

    CHtmlView捕获了很多事件。把那些代码照搬到CDialog就可以。
      

  2.   

    我就是说这样做太复杂了,我试过跟踪CHtmlView的执行,它用到了很多CView的东西,要全Copy 太复杂了。有没有简单一点的方法???
      

  3.   

    // Microsoft Systems Journal -- January 2000
     // If this code works, it was written by Paul DiLascia.
     // If not, I don't know who wrote it.
     // Compiles with Visual C++ 6.0, runs on Windows 98 and probably Windows NT too.
     //
     class CHtmlCtrl : public CHtmlView {
     public:
        CHtmlCtrl() { }
        ~CHtmlCtrl() { }
     
        BOOL CreateFromStatic(UINT nID, CWnd* pParent);
     
        // Normally, CHtmlView destroys itself in PostNcDestroy,
        // but we don't want to do that for a control since a control
        // is usually implemented as a stack object in a dialog.
        //
        virtual void PostNcDestroy() {  }
     
        // overrides to bypass MFC doc/view frame dependencies
        afx_msg void OnDestroy();
        afx_msg int  OnMouseActivate(CWnd* pDesktopWnd,UINT nHitTest,UINT message);
     
        // override to trap "app:" pseudo protocol
        virtual void OnBeforeNavigate2( LPCTSTR lpszURL,
           DWORD nFlags,
           LPCTSTR lpszTargetFrameName,
           CByteArray& baPostedData,
           LPCTSTR lpszHeaders,
           BOOL* pbCancel );
     
        // override to handle links to "app:mumble...". lpszWhere will be "mumble"
        virtual void OnAppCmd(LPCTSTR lpszWhere);
     
        DECLARE_MESSAGE_MAP();
        DECLARE_DYNAMIC(CHtmlCtrl)
     };HtmlCtrl.cpp  // Microsoft Systems Journal -- January 2000
     // If this code works, it was written by Paul DiLascia.
     // If not, I don't know who wrote it.
     // Compiles with Visual C++ 6.0, runs on Windows 98 and probably Windows NT too.
     //
     #include "StdAfx.h"
     #include "HtmlCtrl.h"
     
     #ifdef _DEBUG
     #define new DEBUG_NEW
     #undef THIS_FILE
     static char THIS_FILE[] = __FILE__;
     #endif
     
     IMPLEMENT_DYNAMIC(CHtmlCtrl, CHtmlView)
     BEGIN_MESSAGE_MAP(CHtmlCtrl, CHtmlView)
        ON_WM_DESTROY()
        ON_WM_MOUSEACTIVATE()
     END_MESSAGE_MAP()
     
     //////////////////
     // Create control in same position as an existing static control with
     // the same ID (could be any kind of control, really)
     //
     BOOL CHtmlCtrl::CreateFromStatic(UINT nID, CWnd* pParent)
     {
        CStatic wndStatic;
        if (!wndStatic.SubclassDlgItem(nID, pParent))
           return FALSE;
     
        // Get static control rect, convert to parent's client coords.
        CRect rc;
        wndStatic.GetWindowRect(&rc);
        pParent->ScreenToClient(&rc);
        wndStatic.DestroyWindow();
     
        // create HTML control (CHtmlView)
        return Create(NULL,                  // class name
           NULL,                             // title
           (WS_CHILD | WS_VISIBLE ),         // style
           rc,                               // rectangle
           pParent,                          // parent
           nID,                              // control ID
           NULL);                            // frame/doc context not used
     }
     
     ////////////////
     // Override to avoid CView stuff that assumes a frame.
     //
     void CHtmlCtrl::OnDestroy()
     {
        // This is probably unecessary since ~CHtmlView does it, but
        // safer to mimic CHtmlView::OnDestroy.
        if (m_pBrowserApp) {
           m_pBrowserApp->Release();
           m_pBrowserApp = NULL;
        }
        CWnd::OnDestroy(); // bypass CView doc/frame stuff
     }
     
     ////////////////
     // Override to avoid CView stuff that assumes a frame.
     //
     int CHtmlCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
     {
        // bypass CView doc/frame stuff
        return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, msg);
     }
     
     //////////////////
     // Override navigation handler to pass to "app:" links to virtual handler.
     // Cancels the navigation in the browser, since app: is a pseudo-protocol.
     //
     void CHtmlCtrl::OnBeforeNavigate2( LPCTSTR lpszURL,
        DWORD nFlags,
        LPCTSTR lpszTargetFrameName,
        CByteArray& baPostedData,
        LPCTSTR lpszHeaders,
        BOOL* pbCancel )
     {
        const char APP_PROTOCOL[] = "app:";
        int len = _tcslen(APP_PROTOCOL);
        if (_tcsnicmp(lpszURL, APP_PROTOCOL, len)==0) {
           OnAppCmd(lpszURL + len);
           *pbCancel = TRUE;
        }
     }
     
     void CHtmlCtrl::OnAppCmd(LPCTSTR lpszWhere)
     {
        // default: do nothing
    }
      

  4.   

    TO jiangsheng(蒋晟):程序我看了,程序本质还是相当于借用了MFC的东西,还有一点问题,就是在
    使用CHtmlView的事件时,申明事件宏时,连接程序诗会出错,原因就是CDialog无法使用EventSinkMap,我想要知道的是如何才能像基类为CHtmlView的程序一样使用CHtmlView提供的事件响应函数。不过还是得谢谢你的热情。