在VC6中创建一单文档工程,可命名为RegExplorer,前5步可以按默认方式进行,在AppWizard对话框的Step6中,选取视图类的基类为ClistView。
为支持树与列表的表现形式,必须还要手工加入CregLeftView类,基类为CtreeView。并对各类对象的通信与显示进行必要的设置。
对CregExplorerApp类的InitInstance()进行一些修改
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CRegExplorerDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CRegLeftView));//本为CRegExplorerView
在CmainFrame类中加入protected型的成员变量CSplitterWnd m_wndSplitter用于实现窗口的分割,在MainFrm.cpp中加入#include "RegLeftView.h"
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
if (!m_wndSplitter.CreateStatic(this, 1, 2))
return FALSE;
if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CRegLeftView), CSize(100, 100), pContext) ||
!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRegExplorerView), CSize(100, 100), pContext))
{
m_wndSplitter.DestroyWindow();
return FALSE;
}
m_wndSplitter.SetColumnInfo(0, 200, 100);
return TRUE;
}
对文档类CregExplorerDoc的类定义前可加入class CRegExplorerView;并加入public型的CregExplorerView指针* m_RegExplorerView;用文档类进行对象之间的通信。
左边树型CregLeftView类的设计:
1. 和文档类进行通信的代码:
在类定义前加入class CRegExplorerDoc;并在类中实现public型的成员函数
CRegExplorerDoc* CRegLeftView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CRegExplorerDoc)));
return (CRegExplorerDoc*)m_pDocument;
}