读书人

分割视图程序崩溃,该如何处理

发布时间: 2013-10-21 17:00:48 作者: rapoo

分割视图,程序崩溃


class CMainFrame : public CFrameWnd
{
private:
CSplitterWndm_splitterWnd;
CSplitterWndm_splitterWnd2;




BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: 在此添加专用代码和/或调用基类

m_splitterWnd.CreateStatic(this,2,1);
m_splitterWnd2.CreateStatic(&m_splitterWnd,1,2);

CRect rect;
GetClientRect(&rect);

m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CSpiltterWndView),CSize(50,50),pContext);
m_splitterWnd.CreateView(0,1,RUNTIME_CLASS(CMyFormView),CSize(50,50),pContext); //崩溃的语句,在这里

m_splitterWnd2.CreateView(1,0,RUNTIME_CLASS(CMyScrollView),CSize(50,50),pContext);

return CFrameWnd::OnCreateClient(lpcs, pContext);
}


3种不同的视图


CMainFrame类里,我并没有添加这3个视图的类的任何对象或者指针成员

[解决办法]
m_splitterWnd.CreateStatic(this,2,1); //这里是2行1列
......
m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CSpiltterWndView),CSize(0,0),pContext);
m_splitterWnd.CreateView(0,1,RUNTIME_CLASS(CMyFormView),CSize(0,0),pContext);

//////////////////////////
所以应该是:
m_splitterWnd.CreateView(0,0,RUNTIME_CLASS(CSpiltterWndView),CSize(0,0),pContext);
m_splitterWnd.CreateView(1,0,RUNTIME_CLASS(CMyFormView),CSize(0,0),pContext);

读书人网 >VC/MFC

热点推荐