VIEWEX Sample: Demonstrates Multiple Views, Scroll Views, and Splitter Windows
The VIEWEX sample illustrates the following.
- A static splitter window in which the order and number of panes never change and the panes are usually of different view classes.
- A form view (CFormView) that stays synchronized with other views on the same document.
- Dialog data exchange (DDX), specifically of radio group button data.
The document in VIEWEX is simple. Its data consists of a string and its color.
Building and Running the Sample
To build and run the VIEWEX sample
- Open the solution viewex.sln.
- On the Build menu, click Build.
- On the Debug menu, click Start Without Debugging.
When you first run VIEWEX, it presents a New dialog box in which you select the type of document window to be illustrated:
- Simple Text displays the string, using the current color, centered in the window.
- Input Form View provides a form (a CFormView) in which you can change the string in an edit control, and change the color by selecting from a radio button group.
- Splitter Frame with both Simple Text and Input Form displays in two side-by-side panes of a splitter window. When you change the string (character by character) or color in the Input Form, the Simple Text view automatically reflects the change.
- Three-way Splitter Frame displays the Input Form view in one splitter window pane. The other pane is divided into two subpanes by a splitter bar: The upper subpane displays a Simple Text view; the lower subpane displays a Color view. The Color view simply paints itself entirely in the current color.
You can change the string by using the edit control in the input form and by clicking Change Data on the Edit menu.
You can also view multiple documents at a time. For the sake of simplicity, however, you cannot save or reopen documents, nor can you view the same document in more than one of the above windows.
Static Splitter Window
In VIEWEX, the MDI child window creates a 1-by-2 splitter window within its client area by overriding OnCreateClient. In the case of the three-way splitter, VIEWEX embeds a second 2-by-1 splitter window within the right-side pane of the 1-by-2 splitter window.
VIEWEX calls CSplitterWnd::CreateStatic instead of CSplitterWnd::Create to create static splitter windows instead of dynamic splitter windows. Each pane of VIEWEX's splitter window has a different view class. VIEWEX calls CSplitterWnd::CreateView to specify the CView derived class for each pane. In the case of the first pane, VIEWEX uses the view class specific in the document template object, which is passed to OnCreateClient in the m_pNewViewClass member of the CCreateContext. In the case of other panes, VIEWEX specifies the RUNTIME_CLASS of the view.
CInputView illustrates synchronizing a form view with other views, so when the user enters data in one of the fields, the change is immediately reflected in other views. CInputView accomplishes this by mapping ON_EN_CHANGE and ON_BN_CLICKED for all of its controls to a central OnDataChange message handler. OnDataChange calls CView::UpdateData to transfer data from the screen to the member variables of CInputView and then calls the document's UpdateAllViews to inform the other views about the change.
Dialog Data Exchange (DDX)
VIEWEX's CInputView illustrates dialog data exchange (DDX) of radio group button data. In Iputvw.h, note that only the first button in the radio group is mapped to the member variable
m_iColor in CInputView::DoDataExchange.
m_iColor is a zero-based ordinal value (int) representing which radio button is selected.
This sample demonstrates the following keywords:
CDC::FillRect; CDialog::DoModal; CDocument::OnNewDocument; CDocument::UpdateAllViews; CFrameWnd::LoadFrame; CFrameWnd::OnCreateClient; CFrameWnd::SetActiveView; CObject::Serialize; CRect::Height; CRect::Width; CSplitterWnd::CreateStatic; CSplitterWnd::CreateView; CSplitterWnd::GetPane; CSplitterWnd::IdFromRowCol; CString::GetLength; CView::GetDocument; CView::OnActivateView; CView::OnDraw; CView::OnUpdate; CWinApp::AddDocTemplate; CWinApp::InitInstance; CWinApp::OnFileNew; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::OnMouseActivate; CWnd::ShowWindow; CWnd::UpdateData; CWnd::UpdateWindow; RGB; SetBkMode; SetTextAlign; SetTextColor; TextOut; max
Note Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.