CreateStatic CreateView

本文介绍如何使用MFC中的CSplitterWnd类创建静态拆分窗口,并演示了通过CreateStatic方法设置拆分窗口的行数和列数,以及通过CreateView方法创建拆分窗口的各个视图。

CSplitterWnd::CreateStatic

This method creates a static splitter window.

BOOL CreateStatic( 
CWnd* pParentWnd, 
int nRows, 
int nCols, 
DWORD dwStyle = WS_CHILD | WS_VISIBLE, 
UINT nID = AFX_IDW_PANE_FIRST ); 
Parameters
pParentWnd
Specifies the parent frame window of the splitter window.
nRows
Specifies the number of rows. This value must not exceed 16.
nCols
Specifies the number of columns. This value must not exceed 16.
dwStyle
Specifies the window style.
nID
Specifies the child window ID of the window. The ID can be AFX_IDW_PANE_FIRST unless the splitter window is nested inside another splitter window.
Return Value

Nonzero if it is successful; otherwise, it is zero.

CSplitterWnd::CreateView

This method creates the panes for a static splitter window. All panes of a static splitter window must be created before the framework displays the splitter.

The framework also calls this method to create new panes when the user of a dynamic splitter window splits a pane, row, or column.

virtual BOOL CreateView( 
int row, 
int col, 
CRuntimeClass* pViewClass, 
SIZE sizeInit, 
CCreateContext* pContext ); 
Parameters
row
Specifies the splitter window row in which to place the new view.
col
Specifies the splitter window column in which to place the new view.
pViewClass
Specifies the CRuntimeClass of the new view.
sizeInit
Specifies the initial size of the new view.
pContext
Specifies a pointer to a creation context used to create the view. This pointer is usually the pContext passed into the parent frame’s overridden CFrameWnd::OnCreateClient method in which the splitter window is being created.
Return Value

Nonzero if it is successful; otherwise, it is zero.

比如

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	split.CreateStatic(this,2,1);
	split.CreateView(0,0,RUNTIME_CLASS(CTest3View),CSize(0,150),pContext);
	split.CreateView(1,0,RUNTIME_CLASS(CTest3View),CSize(0,0),pContext);
	return CMDIChildWnd::OnCreateClient(lpcs, pContext);
}

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	split.CreateStatic(this,1,2);
	split.CreateView(0,0,RUNTIME_CLASS(CTest3View),CSize(150,0),pContext);
	split.CreateView(0,1,RUNTIME_CLASS(CTest3View),CSize(0,0),pContext);
	return CMDIChildWnd::OnCreateClient(lpcs, pContext);
}


需要在theApp所在文件中的pDocTemplate项目制定为NULL
	CMultiDocTemplate* pDocTemplate;
	pDocTemplate = new CMultiDocTemplate(
		IDR_TEST3TYPE,
		RUNTIME_CLASS(CTest3Doc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		NULL);
	AddDocTemplate(pDocTemplate);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值