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 parentm_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