CreateStatic CreateView

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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);


### 创建 Android SQLite 数据库视图 在 Android 应用程序中创建数据库视图可以通过扩展 `SQLiteOpenHelper` 类并重写其方法来实现。为了创建视图,可以在 `onCreate()` 方法内执行 SQL 命令 `CREATE VIEW`。 对于具体的实现方式,在 MyDatabaseHelper.java 文件中的 `onCreate()` 函数里除了可以定义表之外还可以加入视图的创建语句[^2]: ```java public class MyDatabaseHelper extends SQLiteOpenHelper { public static final String CREATE_BOOK_TABLE = "create table Book(name text, pages integer)"; public static final String CREATE_VIEW_AUTHORS_BOOKS = "CREATE VIEW IF NOT EXISTS AuthorsBooks AS SELECT A.name as author_name, B.name as book_title FROM Author A JOIN Book B ON A.id = B.author_id"; public MyDatabaseHelper(Context context, String name, CursorFactory factory, int version){ super(context, name, factory, version); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_BOOK_TABLE); db.execSQL(CREATE_VIEW_AUTHORS_BOOKS); // 添加此行以创建视图 } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {} } ``` 上述代码片段展示了如何通过 SQL 语句创建名为 `AuthorsBooks` 的视图,该视图连接了两个假设存在的表格——`Author` 和 `Book` 表格,并选择了作者的名字 (`A.name`) 及书籍名称 (`B.name`) 来作为新视图的内容。 值得注意的是,当应用程序首次安装时会调用 `onCreate()` 方法从而建立所需的结构化查询语言 (SQL) 对象如表和视图等。如果以后更新应用程序版本,则可能需要处理好旧数据迁移等问题,这通常是在 `onUpgrade()` 中完成的工作[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值