当CLeftPane从CView继承时,程序运行完好,可是当我把CLeftPane从CFrameWnd继承过来,在程序退出时会报异常,这是怎么回事?不过我的CRightPane是从CFrameWnd继承过来的。是不是拆分窗口的(0,0)位置一定要是从CView继承过来呢???各位大虾帮我看看吧,多谢了。BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
CCreateContext* pContext)
{ CRect rc;
this->GetClientRect(rc);
int iProjWidth = rc.Width()*0.3; if (!m_wndSplitter.CreateStatic(this, 1,2))
return false;
//CLeftPane如果从CFrameWnd继承,程序退出报错!
//CLeftPane如果从CView继承,程序运行正常
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftPane),      CSize(iProjWidth,rc.Height()), pContext))
return false;
//CRightPane从CFrameWnd继承,
if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightPane),  CSize(rc.Width()-iProjWidth,rc.Height()), pContext))
return false;
return true;
}如果我把CLeftPane从CView继承过来,以下代码怎么不起作用?(看不到上下两个拆分窗口)
int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return 0;
}如果我把CLeftPane从CFrameWnd继承过来,以下代码可以实现(可以看到上下两个拆分窗口),但就是退出程序时报异常,到底是怎么回事?
BOOL CLeftPane::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
CRect rc;
this->GetClientRect(rc);
if (!m_Splitter.CreateStatic(this, 2, 1))
return false;
if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
return false;
if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
return false;
return true;
}
程序异常时停在winfrm.cpp的”***“处void CFrameWnd::OnClose()
{
if (m_lpfnCloseProc != NULL)
(*m_lpfnCloseProc)(this); // Note: only queries the active document
CDocument* pDocument = GetActiveDocument();
if (pDocument != NULL && !pDocument->CanCloseFrame(this))
{
// document can't close right now -- don't close it
return;
}
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this)
{
// attempt to save all documents
if (pDocument == NULL && !pApp->SaveAllModified())
return;     // don't close it // hide the application's windows before closing all the documents
pApp->HideApplication(); // close all documents first
pApp->CloseAllDocuments(FALSE); // don't exit if there are outstanding component objects
if (!AfxOleCanExitApp())
{
// take user out of control of the app
AfxOleSetUserCtrl(FALSE); // don't destroy the main window and close down just yet
//  (there are outstanding component (OLE) objects)
return;
} // there are cases where destroying the documents may destroy the
//  main window of the application.
if (!afxContextIsDLL && pApp->m_pMainWnd == NULL)
{
AfxPostQuitMessage(0);
return;
}
} // detect the case that this is the last frame on the document and
// shut down with OnCloseDocument instead.
if (pDocument != NULL && pDocument->m_bAutoDelete)
{
BOOL bOtherFrame = FALSE;
//***  程序报错时停在此处
POSITION pos = pDocument->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument->GetNextView(pos);
ASSERT_VALID(pView);
if (pView->GetParentFrame() != this)
{
bOtherFrame = TRUE;
break;
}
}
if (!bOtherFrame)
{
pDocument->OnCloseDocument();
return;
} // allow the document to cleanup before the window is destroyed
pDocument->PreCloseFrame(this);
} // then destroy the window
DestroyWindow();
}

解决方案 »

  1.   

    一般应该两个都从VIEW继承吧,为什么从CFRAMEWAND里继承?
      

  2.   

    我是这样实现的BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(
    !m_MainWndSplitter.CreateStatic(this,1,2)||
    !m_MainWndSplitter.CreateView(0,0,RUNTIME_CLASS(CConfigForm),CSize(200,0),pContext)||
    !m_MsgWndSplitter.CreateStatic(&m_MainWndSplitter,2,1,WS_CHILD|WS_VISIBLE,m_MainWndSplitter.IdFromRowCol(0,1))||
    !m_MsgWndSplitter.CreateView(0,0,RUNTIME_CLASS(CSInterFaceView),CSize(0,300),pContext)||
    !m_MsgWndSplitter.CreateView(1,0,RUNTIME_CLASS(CStateView),CSize(0,0),pContext)
    )return false;

    return true;
    }
      

  3.   

    to seilfer2000(鬼手韩特) :
    我从CFrameWnd继承就是需要在继续在这个FrameWnd中创建一个分割窗口,用View好像不能创建出来,你可以看看上面我贴出来的代码,程序没有报错,但是没有产生所需要的分割窗口to dailiangcm(dailiang):
    你的代码我刚才试过了,没有效果的,我想要的是主窗口被分割成一行两列,而每一列又被分割成两行一列。up
      

  4.   

    在CMainFrame里设2个CSplitterWnd变量m_wndSplitter1和m_wndSplitter2第二个在第一个的基础上再进行拆分,一般都是这么实现的
      

  5.   

    我用CView继承,创建了一行两列的分割窗口如果能知道如何在每一个CView的区域再创建一个两行一列的分割窗口,那问题也可以解决了,现在我就是不知道如何在CView类中再去创建,我想到的是如下代码,可是一运行,什么都没有创建出来,似乎如下代码没有任何效果一样,why????int CLeftView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;
    CRect rc;
    this->GetClientRect(rc);
    if (!m_Splitter.CreateStatic(this, 2, 1))
    return false;
    CCreateContext *pContext = (CCreateContext*) lpCreateStruct->lpCreateParams;
    if (!m_Splitter.CreateView(0, 0, RUNTIME_CLASS(CProjectListDlg), CSize(rc.Width(), rc.Height()/3), pContext))
    return false;
    if (!m_Splitter.CreateView(1, 0, RUNTIME_CLASS(CBaseInfoDlg), CSize(rc.Width(), rc.Height()-rc.Height()/3), pContext))
    return false;
    return 0;
    }在线等待!!!急啊!!!!
      

  6.   


        VERIFY(m_wndSplitter.CreateStatic(this, 2, 1));
        VERIFY(m_wndSplitter.CreateView(1, 0,RUNTIME_CLASS(CMyView),
                                        CSize(100, 100), pContext));
    m_wndSplitter.SetRowInfo(0,200,0);    VERIFY(m_wndSplitter1.CreateStatic(&m_wndSplitter, 1, 2,WS_CHILD|WS_VISIBLE,m_wndSplitter.IdFromRowCol(0,0)));
    VERIFY(m_wndSplitter1.CreateView(0, 0, RUNTIME_CLASS(CSecView),
                                        CSize(100, 200), pContext));
       VERIFY(m_wndSplitter1.CreateView(0, 1,RUNTIME_CLASS(CLstView),
                                        CSize(100, 200), pContext));m_wndSplitter,m_wndSplitter1是分别定义的两个变量,其他的看着改就可以了。
      

  7.   

    刚才忘了说了,上面的代码是在CMainFrame里写的。不好意思。
      

  8.   

    Step by Step
    Step 1.首先Ctrl+W添加两个新类
    CMyListView : CListView
    CMyTreeView : CTreeViewStep 2.然后Project->Add to Project->Components and Controls
    进入Visual C++ Components文件夹
    选择添加Splitter Bar
    一路OK就OK3.你会发现在CMainFrame中发现增加了一下函数
    BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
    删除其中所有的内容
    添加以下代码
    m_wndSplitter.CreateStatic(this ,1, 2);
    m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CTreeView), CSize(202, 0), pContext);
    m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CListView), CSize(0, 0), pContext);return TRUE;Step 4.加入CTreeView,CListView的头文件即可Step 5.如有任何问题,可以发信给我
    [email protected]
    我尽力帮你解决---------------------------
                      May you succeed!
                        -------------------------------