MFC SDI中添加Split Window

Splitter Window是一种分割栏,可以框架分成多个不同的部分。在添加Splitter Window之前,我们有必要正式的了解一下CSplitterWnd类。

CSplitterWnd在MSDN上是如下解释的;

Provides the functionality of a splitter window, which is a window that contains multiple panes。

为一个包含多个面板区的分割窗提供函数功能。

一个CSpliterWnd对象通常嵌入在CFrameWnd或者CMDIChildWnd对象中,创建一个CSplitterWnd一般有如下步骤:

1、在CFrameWnd中或者CMDIChildWnd中添加一个成员变量

2、重载父框架CFrameWnd或者CMDIChildWnd的OnCreateClient成员函数。

3.在OnCreateClient成员函数中使用CSplitterWnd的Create或者CreateStatic创建动态或者静态分割窗。

接下来,我们将先了解CSplitterWnd的一下成员函数,再在实际的例子中创建一个Splitter Window。

virtual BOOL Create(CWnd* pParentWnd,int nMaxRows,int nMaxCols,SIZE sizeMin,CCreateContext* pContext,
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | SPLS_DYNAMIC_SPLIT, UINT nID = AFX_IDW_PANE_FIRST);
virtual BOOL CreateStatic(CWnd* pParentWnd,int nRows,int nCols,DWORD dwStyle = WS_CHILD | WS_VISIBLE,UINT nID = AFX_IDW_PANE_FIRST);
virtual BOOL CreateView(int row,int col, CRuntimeClass* pViewClass,SIZE sizeInit,CCreateContext* pContext );

上述三个函数是比较常用的三个函数,分别是动态分割窗的创建函数、静态分割窗创建函数和视图填充函数。

下面我们来建立一个实际SDI的例子。首先创建一个SDI,我们可以有两种方式的来创建(我的环境是VS2008),一种在构建SDI中勾上Split Window选项,如下图。立。

 
另一种按照SDI中的步骤建立:
我所建立的SDI的类图如下:
 
1、首先我们将在CMainFrame类的头文件中声明一个CSplitterWnd变量,如CSplitterWnd m_CSplitterWnd;
 
2、右击上面类图中的CMainFrame类,点击属性,在属性的Override的选项中,现则OnCreateClient函数,在OnCreateClient函数中添加如下代码:
 
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
CRect rect;
GetClientRect(&rect);
 
if  (!m_CSplitterWnd.CreateStatic( this ,1,3))
{
return  FALSE;
}
if  (!m_CSplitterWnd.CreateView( 0, 0,
RUNTIME_CLASS(CCameraManageDemoView),
CSize(rect.Width()/6, rect.Height()), pContext ) )
{
return  FALSE;
}
 
if  ( !m_CSplitterWnd.CreateView( 0, 1,
RUNTIME_CLASS(CImageDispView),
CSize(rect.Width()*2/3, rect.Height()), pContext ) )
{
return  FALSE;
}
if  ( !m_CSplitterWnd.CreateView( 0, 2,
RUNTIME_CLASS(CImageControlView),
CSize(rect.Width()/6, rect.Height()), pContext ) )
{
return  FALSE;
}
 
return  TRUE;

 3.如代码所示,我们使用了两个三个视图,分别为CCameraManageDemoView、CImageDispView、CImageDispView。我们在右击添加类,base class为CFormView。

  4、创建好CFormView类将他们include到CMainFrm的CPP文件中.

  5、最后在新增加的视图类的头文件中include "CCameraManageDemoDoc.h"。因为View中需要使用document中的函数。

运行后就能出来split window。


转自:http://www.cnblogs.com/codeengineer/archive/2013/03/29/2988233.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值