MFC创建分割视图

来源:互联网 发布:哈佛 歧视 知乎 编辑:程序博客网 时间:2024/05/21 08:00

使用MFC创建分割视图:

1、创建一个新的MFC单文档工程


2、插入对话框资源,并注意更改对话框属性


3、添加一个基于上述设计对话框的CFromView

使用向导Ctrl+W创建一个CMyView


4、重载CMainFrame中的OnCreateClient函数

可使用Ctrl+W呼出向导进行

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) {// TODO: Add your specialized code here and/or call the base classreturn CFrameWnd::OnCreateClient(lpcs, pContext);}

在成员中添加变量CSplitterWnd m_wndSplitter1,m_wndSplitter2;

在CMainFrame的文件开始处包含MyView.h   #include "MyView.h"

现在开始创建一个一行两列的窗体


重载函数现在为

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) {// TODO: Add your specialized code here and/or call the base classif(!m_wndSplitter1.CreateStatic(this,1,2))return FALSE;if(!m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(500,600),pContext))return FALSE;if(!m_wndSplitter1.CreateView(0,1,RUNTIME_CLASS(CMyView),CSize(100,600),pContext))return FALSE;return TRUE;}
得到的分割视图为

5、对右边一行的视图再次进行分割

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) {// TODO: Add your specialized code here and/or call the base classif(!m_wndSplitter1.CreateStatic(this,1,2))return FALSE;if(!m_wndSplitter1.CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(500,600),pContext))return FALSE;//再次分割if(!m_wndSplitter2.CreateStatic(&m_wndSplitter1,2,1,WS_CHILD|WS_VISIBLE,m_wndSplitter1.IdFromRowCol(0,1)))return FALSE;//右方视图创建if(!m_wndSplitter2.CreateView(0,0,RUNTIME_CLASS(CMyView),CSize(100,200),pContext))return FALSE;if(!m_wndSplitter2.CreateView(1,0,RUNTIME_CLASS(CMyView),CSize(100,400),pContext))return FALSE;return TRUE;}

效果图



0 0
原创粉丝点击