mfc对话框的二次切分

在这里插入代码片一:首先需要建两个类,目的是到时候定义划分的窗口种类
点击项目:项目图片再点击类向导
在这里插入图片描述鼠标移动至添加类,点击添加mfc类, 类名命名为FrameList ,基类选 CListView, 类名命名为FrameEdit 基类选 CEditView。
随后点击类向导,添加消息函数WM_Create.再在消息函数中添加如下代码

CCreateContext ctxList, ctxEdit;
ctxList.m_pNewViewClass = RUNTIME_CLASS(FrameEdit);
ctxList.m_pCurrentDoc = NULL;
ctxList.m_pNewDocTemplate = NULL;
ctxList.m_pLastView = NULL;
ctxList.m_pCurrentFrame = NULL;

ctxEdit.m_pNewViewClass = RUNTIME_CLASS(FrameEdit);
ctxEdit.m_pCurrentDoc = NULL;
ctxEdit.m_pNewDocTemplate = NULL;
ctxEdit.m_pLastView = NULL;
ctxEdit.m_pCurrentFrame = NULL;

// Because the CFrameWnd needs a window class, we will create
// a new one. I just copied the sample from MSDN Help.
// When using it in your project, you may keep CS_VREDRAW and
// CS_HREDRAW and then throw the other three parameters.
CString strMyClass = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH)::GetStockObject(WHITE_BRUSH), ::LoadIcon(NULL, IDI_APPLICATION));

// Create the frame window with "this" as the parent
m_pFrameWnd = new CFrameWnd();
m_pFrameWnd->Create(strMyClass, _T(""), WS_CHILD, CRect(0, 0, 50, 50), this);
m_pFrameWnd->ShowWindow(SW_SHOW);
m_pFrameWnd->MoveWindow(0, 0, 500, 400);

// and finally, create the splitter with the frame as
// the parent
	m_wndSplitter.CreateStatic(m_pFrameWnd, 1, 2);//建立第一层构架
//m_wndSplitter.CreateStatic(this, 1, 2);//建立第一层构架
m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(FrameList), CSize(200,200), &ctxList);
m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(FrameEdit), CSize(200, 200), &ctxEdit);
m_wndSplitter2.CreateStatic(&m_wndSplitter, 3, 1, WS_CHILD | WS_VISIBLE | WS_BORDER,
	m_wndSplitter.IdFromRowCol(0,0));//建立第二层构架
m_wndSplitter.DeleteView(0,0);//动态拆分
m_wndSplitter2.CreateView(0, 0, RUNTIME_CLASS(FrameList), CSize(100, 100), &ctxList);
m_wndSplitter2.CreateView(1, 0, RUNTIME_CLASS(FrameList), CSize(100,100), &ctxList);
m_wndSplitter2.CreateView(2, 0, RUNTIME_CLASS(FrameList), CSize(100, 100), &ctxList);
m_wndSplitter3.CreateStatic(&m_wndSplitter2, 1, 2, WS_CHILD | WS_VISIBLE | WS_BORDER,
	m_wndSplitter2.IdFromRowCol(0, 0));
m_wndSplitter3.CreateView(0, 0, RUNTIME_CLASS(FrameList), CSize(100, 100), &ctxList);
return 0;

至此,主题部分写完。随后,我们需要在消息处理函数OnInitDialog中添加如下代码

   // TODO: 在此添加额外的初始化代码
CRect rect;
// Get the rectangle of the custom window. The custom window
// is just a a big button that is not visible and is disabled.
// It's a trick to not use coordinates directly.
//GetDlgItem(IDD_THREECUT_DIALOG)->
	GetWindowRect(&rect);

// Move the splitter
ScreenToClient(&rect);
m_pFrameWnd->MoveWindow(&rect);
m_pFrameWnd->ShowWindow(SW_SHOW);
//m_wndSplitter.MoveWindow(0, 0, rect.Width(), rect.Height());
//m_wndSplitter.ShowWindow(SW_SHOW);
return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE

写成这样还是会报错,因为很多变量没有定义,我们需要在 XXXDlg.h头文件中定义如下变量

  public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
CFrameWnd *m_pFrameWnd;
CSplitterWnd m_wndSplitter;
CSplitterWnd m_wndSplitter2;

到此,所有代码全部写完。运行时会有个中断,我也没有弄清原因,点忽略就会看到想要的结果。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

物联网小镇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值