CSplitterWnd在OnCreateClient()函数:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
CRect frmRC;
GetClientRect(frmRC);
if(!m_wndSplitter.CreateStatic(this,1,2))
return FALSE;
if(!m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CLeftView),CSize(200,frmRC.Height()),pContext))
return FALSE;
if(!m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CRightView),CSize(frmRC.Width()-200,frmRC.Height()),pContext))
return FALSE;
return TRUE;
// return CFrameWnd::OnCreateClient(lpcs, pContext);
}
上面在Frame中实现视图分割,关键是CLeftView和CRightView。右边CRightView应该如何定义?CView、CFormView、CDialog?
CLeftView使用CTreeView实现:
void CLeftView::OnInitialUpdate()
{
CTreeView::OnInitialUpdate();
::SetWindowLong(m_hWnd,GWL_STYLE,WS_VISIBLE|WS_TABSTOP
|WS_CHILD|WS_BORDER|TVS_HASBUTTONS |TVS_LINESATROOT|TVS_HASLINES);
CTreeCtrl* pCtrl = &GetTreeCtrl();
TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("根节点");
HTREEITEM hChild1 = pCtrl->InsertItem(TVIF_TEXT,
_T("通信控制机1"), 0, 0, 0, 0, 0, hRoot, NULL);
HTREEITEM hChild2 = pCtrl->InsertItem(_T("通信控制机2"),
0, 0, hRoot, hChild1);
pCtrl->InsertItem(_T("电台1"), hChild1, TVI_SORT);
pCtrl->InsertItem(_T("电台2"), hChild1, TVI_SORT);
pCtrl->InsertItem(_T("电台3"), hChild1, TVI_SORT);
pCtrl->InsertItem(_T("电台3"), hChild2, TVI_SORT);
pCtrl->InsertItem(_T("电台2"), hChild2, TVI_SORT);
pCtrl->InsertItem(_T("电台1"), hChild2, TVI_SORT);
pCtrl->Expand(hRoot,TVE_EXPAND);
}
上面实现向树视图插入节点。
void CLeftView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 函数响应当树节点选中改变时。
当OnSelchanged时,希望右边视图链接上已做好的不同的对话框以显示不同的数据控件(静态文本框、文本框、按钮等)。右边如何实现???