请教!如何替换CsplitterWnd中的某个View(快疯了,大侠快来救命)
isis 2004-04-06 07:19:17 CsplitterWnd中需要通过用户在运行期手动决定显示某个View
所有的View都是预先定义好了,保存在CsplitterWnd 中的
CPtrArray m_ptrarrayRCView数组中(其中任意的有多个CView的子类,比如CHtmlView)
用户需要调用CsplitterWnd 中自定义函数
ReplaceView(CRuntimeClass* pRCView),把从m_ptrarrayRCView取出的一个CView类型pRCView把原来的位于CsplitterWnd区域(0, 0)的哪个替换掉
请教大家如何做
我试图通过下面的代码来运行
BOOL Tab_SplitterWnd::ReplaceView(CRuntimeClass* pRCView)
{
CView* pOldView = GetParentFrame()->GetActiveView();
CView* pNewView = (CView*)pRCView;
::SetParent(pNewView->m_hWnd, GetParentFrame()->m_hWnd);
GetParentFrame()->SetActiveView(pNewView);
pNewView->ShowWindow(SW_SHOW);
pOldView->ShowWindow(SW_HIDE);
::SetWindowLong(pNewView->m_hWnd, GWL_ID, AFX_IDW_PANE_FIRST);
RecalcLayout();
return true;
}
但是不行
总是在SetActiveView中的ASSERT(IsChild(pViewNew));中出错
但是我设置了SetParent,不知道为什么
试图通过
BOOL Tab_SplitterWnd::ReplaceView(CRuntimeClass* pRCView)
{
CCreateContext context;
SIZE size;
CRect rect;
CView* pOldView = GetParentFrame()->GetActiveView();
CView* pNewView = (CView*)pRCView;
CDocument* pDoc = pOldView->GetDocument();
context.m_pNewViewClass = pRCView;
context.m_pCurrentDoc = pDoc;
context.m_pNewDocTemplate = pDoc->GetDocTemplate();
context.m_pLastView = NULL;
context.m_pCurrentFrame = GetParentFrame();
pOldView->GetClientRect( &rect );
size.cx = rect.right;
size.cy = rect.bottom;
CreateView( 0, 0, pRCView, size, &context);
GetParentFrame()->SetActiveView(pNewView);
RecalcLayout();
}
但是会出现
TRACE2("Error: CreateView - pane already exists for row %d, col %d.\n",
row, col);的Assertion错误
于是我在CreateView前面加入了pOldView ->DestoryWindow()
但是出现Violation Access错误