想要获得一个内含左右窗口的框架有几种方法,其中一种是使用splitwnd来分割,
要想用splitwnd来分割窗口,需要在mainframe中进行操作,首先要重载OnCreateClient事件,
该事件要先于mainframe的OnCreate事件,顺序OnCreateHelper——>OnCreateClient——>OnCreate这么一个顺序(大概是,在深入浅出中有介绍),
然后要定义splitwnd类
protected:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
CSplitterWnd m_wndSplit;
然后其编写如下,其中CMyTree是视图列表显示窗口,CPCSWView是第一个显示的视图,因为不想打开程序后发现后边是空白区域
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
m_wndSplit.CreateStatic(this,1,2); //这里的1——row,2——col,意思是分为1行2列,
m_wndSplit.CreateView(0,0,RUNTIME_CLASS(CMyTree),CSize(100,100),NULL); //头两个参数是row和所处col坐标
m_wndSplit.CreateView(0,1,RUNTIME_CLASS(CPCSWView),CSize(100,100),NULL);
return TRUE;
// return CMDIFrameWnd::OnCreateClient(lpcs, pContext);
}
这样之后,就可以打开程序并呈现一个简单的左右两个显示区域了。