具体做法:
1. vc2005对话框MFC程序里,建立一个对话框,添加类:CMyFormView1,基类为CFormView;
2. 建立第二个对话框,添加类:CMyFormView2,基类为CFormView;
3. 在主对话框.h头文件里声明:
public:
CFrameWnd* m_pMyFrame;
CSplitterWnd m_cSplitter;
4. 在主对话框.cpp实现文件OnCreate函数里添加:
// 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_pMyFrame = new CFrameWnd;
m_pMyFrame->Create(strMyClass,L"", WS_CHILD, CRect(0,0,300,300), this);
m_pMyFrame->ShowWindow(SW_SHOW);
// and finally, create the splitter with the frame as the parent
m_cSplitter.CreateStatic(m_pMyFrame,1, 2); //在Frame里切分视图窗口为1×2,就是一行两列
m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CMyFormView1), CSize(100,100), NULL);//第一行一列
m_cSplitter.CreateView(0,1, RUNTIME_CLASS(CMyFormView2), CSize(100,100), NULL);//第一行二列