VIEWEX: Demonstrates Multiple Views, Scroll Views, and Splitter Windows

Click to open or copy the VIEWEX project files.

The VIEWEX sample illustrates the following.

The document in VIEWEX is simple. Its data consists of a string and its color.

When you first run VIEWEX, it presents a New dialog box in which you select the type of document window to be illustrated:

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.

Form 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. If you use ClassWizard to view the member variables of CInputView or if you look at the CInputView::DoDataExchange written by ClassWizard in Iputvw.h, you will notice that only the first button in the radio group is mapped to the member variable m_iColor. This 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::Enable3dControls; CWinApp::InitInstance; CWinApp::OnFileNew; CWnd::DoDataExchange; CWnd::GetClientRect; CWnd::OnMouseActivate; CWnd::ShowWindow; CWnd::UpdateData; CWnd::UpdateWindow; RGB; SetBkMode; SetTextAlign; SetTextColor; TextOut; max