在子窗口中嵌入空间(CListCtrl)

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:20:53
子窗口嵌入控件,如下
1.创建单文档应用程序
2.插入以CView为基类的CClientView类
3.框架类头文件声明CSplitterWnd类的对象m_wndSplitter
4.重载框架类的OnCreateClient方法
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_wndSplitter.CreateStatic(this,1,2);
m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CViewCtrlView),CSize(200,100),pContext);
m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CClientView),CSize(200,100),pContext);
return TRUE;
//return CFrameWnd::OnCreateClient(lpcs, pContext);
}
5.CClientView声明ClistCtrl m_List
6.CClientView的OnInitialUpdate方法中创建控件
void CClientView::OnInitialUpdate()
{
CView::OnInitialUpdate();

// TODO: Add your specialized code here and/or call the base class
CRect rect;
GetClientRect(rect);
m_List.Create(LVS_REPORT|LVS_SINGLESEL|LVS_SHOWSELALWAYS|WS_BORDER,
rect,this,10000); //创建列

m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CViewCtrlView),CSize(200,100),pContext);

左边的框架应该为一个CListView视类的派生类,CListView成员函数GetListCtrl()返回一个CListCtrl类的对象的引用,原形如下
CListView::GetListCtrl
CListCtrl& GetListCtrl( ) const;

Return Value

A reference to the list control associated with the view.

在CViewCtrlView::OnInitialUpdate()中写入一样的代码就可以实现在左边框架出现列表。

在任意框架实现的话可以写个虚基类,想要在哪边框架实现就调用该函数