好几次都想随心所欲的控制窗体的分割,这次总算搞明白了,原来这个很搞不明白,因为不知道m_bAutoDelete这个变量是doc内部自有的,所以自己定义了一个变量,结果编译时老出错,还以为微软有问题呢,结果还是自己搞错了。现在把原文贴出来:
How to provide an alternative view of data by using a splitter window
This article was previously published under Q196832
SUMMARY
This article demonstrates how to use a static splitter window in a traditional SDI document-view architecture. The article shows how to design an application that can switch between a single view and a splitter window that can embed as many panes as necessary.
MORE INFORMATION
The solution consists of embedding a pointer to a CSplitterWnd in CMainFrame, as opposed to the recommended way of embedding the CSplitterWnd object. Later, when the application needs to switch from the regular view to the splitter window, this splitter window is created on the heap and initialized by using CreateStatic(), while the regular view is destroyed.
NOTE: To avoid destruction of the CDocument-derived object when the view is destroyed, you need to set its m_bAutoDelete data member to FALSE.
You can easily expand the code to support static splitter windows with different numbers of panes, depending on some run-time conditions.
NOTE: To avoid destruction of the CDocument-derived object when the view is destroyed, you need to set its m_bAutoDelete data member to FALSE.
You can easily expand the code to support static splitter windows with different numbers of panes, depending on some run-time conditions.
Steps to Create Sample
1. | Create a new SDI project. |
2. | Add a SplitterWnd (ID_VIEW_SPLITTERWND) menu item to a View menu. This item turns the splitter window on and off. |
3. | To preserve the document when there is no view associated with it, add add the following code in the CDocument-derived class constructor: |
4. | To avoid resource leaks, you also need to set the flag back to true before the destruction of the last view associated with the document (for example, in the CMainFrame handler of WM_CLOSE: CMainFrame::OnClose()): |
5. | Add a pointer to a CSplitterWnd in the CMainFrame definition: |
6. | Initialize this object in the CMainFrame constructor, and delete it in the destructor: |
7. | Add two new CView-derived classes to your project, representing views that are the panes in your CSplitterWnd. |
8. | Add the following #include statements in your MainFrm.cpp file: |
9. | Use Class Wizard to create a command and an UpdateUI handler in CMainFrame for the menu item you added: |