Click here to Skip to main content
13,247,336 members (84,279 online)
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 10 Jul 2004

Using Multiview

, 10 Jul 2004
Rate this:
Please Sign up or sign in to vote.
How to use multiview


Have you ever want to build an aplication which have more than one view? You can implement it by using a splitter, or multiple views. This article with discuss about using mutiple views, how to use those views, and change between views. Implementation of this, is the html editor, which can change view from design view to html view. These views can have single document or more than one document. In this article, I only use single document.

Using the code

Step 1 Making a new view

Add a new view by inserting a new class with CView / CScrollView / CHtmlView / something else. as the base class. In this tutorial, I will name that class COtherView. Change the constructor and destructor access from protected to public, so that you can call it. Make two CView/CSrollView object, according the base class you created before, named m_pOtherView and m_pOtherView. m_pOtherView is used to store the new view and m_pFirstView to store the first view, so that you can go back to that view.

    CView m_pOtherView;
</CODE>    CView m_pFirstView;

Remember to write the above code and code in step 1 in your App header file. Create a CCreateContext variable to connect the view to the a document, in this case it`s the default document. You can use your own created document if you want, but it`s a bit complex, so i won`t discuss it here. Name the variable context. You will pass this variable as a parameter to create the view. The attribute which store the current document is m_pCurrentDoc.

CDocument* pDoc = ((CFrameWnd*)m_pMainWnd)->GetActiveDocument();
CCreateContext context;
context.m_pCurrentDoc = pDoc;

Before creating the new view, create a new variable m_ID, which hold the new view ID. Set the m_ID base on the first view ID plus 1. AFX_IDW_PANE_FIRST is the first view ID, adding it by one will make sure there is no ID conflict.

Create the new view after ProcessShellCommand in InitInstance ( your App )
m_pOtherView->Create(NULL, NULL, WS_CHILD, rect,
  m_pMainWnd, m_ID, &context);

Step 2 Selecting and viewing the view

First exchange the view ID that we want to show with the previous view ID. You have to do this , so that RecalcLayout do it`s job to the right view, the view that we want to see. Use the SetWindowWord and GetWindowWord to work on the m_hWnd, which is 16-bit.

 UINT temp = ::GetWindowWord(m_pOtherView->m_hWnd, GWL_ID);
::SetWindowWord(m_pOtherView->m_hWnd, GWL_ID,
     ::GetWindowWord(m_pFirstView->m_hWnd, GWL_ID));
::SetWindowWord(m_pFirstView->m_hWnd, GWL_ID, temp);

Hide the previous view and show the next view.


Set the aplication active view with the view we`ve created. Call RecalcLayout to put things in their order.

Step 3 Using and manipulate the view

To get access to the active document, change the code on COtherView::OnDraw. But first include the document header in your source file view. In COtherView add Member Function with function type CMultiViewDoc* and with the name GetDocument(). Write the code below to the function created.

CMultiViewDoc* COtherView::GetDocument()
    return (CMultiViewDoc*)m_pDocument;
void COtherView::OnDraw(CDC* pDC)
    CMultiViewDoc* pDoc = GetDocument();
            // m_str is a member of CMultiViewDoc

Draw on the view as you draw with the usual view.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

CEO Odihost
Indonesia Indonesia
Learned programming since elementry school with QBASIC. Until now have learned a bit about VB, java, html, php, asp, delphi. He is taking his master degree in finance. Currently working for a great company(desain web), and stock trading. Own various website about option strategy, lose weight, and Invest Money.

You may also be interested in...


Comments and Discussions

Generalproblem in switching between views. Pin
T.Ashish19-Feb-09 1:18
memberT.Ashish19-Feb-09 1:18 
QuestionHow about MDI application Pin
Fransiscus Herry27-Sep-08 15:55
memberFransiscus Herry27-Sep-08 15:55 
AnswerRe: How about MDI application Pin
auralius10-Jan-09 3:06
memberauralius10-Jan-09 3:06 
GeneralNice Pin
_808625-Mar-07 19:53
member_808625-Mar-07 19:53 
GeneralRe: Nice Pin
Yulianto.26-Mar-07 1:46
memberYulianto.26-Mar-07 1:46 
Generalabout CListView Pin
wayitech6-Jun-06 5:44
memberwayitech6-Jun-06 5:44 
GeneralCFormView Pin
almasl16-Jul-05 6:29
memberalmasl16-Jul-05 6:29 
GeneralRe: CFormView Pin
Yulianto.7-Jul-05 16:21
memberYulianto.7-Jul-05 16:21 
GeneralRe: CFormView Pin
kedypen26-Dec-05 5:11
memberkedypen26-Dec-05 5:11 
QuestionMultiple Views - Is this correct? Pin
susso27-Dec-04 11:54
membersusso27-Dec-04 11:54 
AnswerRe: Multiple Views - Is this correct? Pin
goodmast3r5-Jan-05 14:39
membergoodmast3r5-Jan-05 14:39 
GeneralON_INIT Event Pin
susso16-Dec-04 11:10
membersusso16-Dec-04 11:10 
GeneralRe: ON_INIT Event Pin
goodmast3r17-Dec-04 22:16
membergoodmast3r17-Dec-04 22:16 
GeneralScrolling Pin
susso11-Dec-04 2:18
membersusso11-Dec-04 2:18 
GeneralRe: Scrolling Pin
goodmast3r12-Dec-04 17:26
membergoodmast3r12-Dec-04 17:26 
GeneralRe: Scrolling Pin
goodmast3r14-Dec-04 16:14
membergoodmast3r14-Dec-04 16:14 
GeneralRe: Scrolling Pin
susso14-Dec-04 19:32
membersusso14-Dec-04 19:32 
GeneralRe: Scrolling Pin
goodmast3r17-Dec-04 22:13
membergoodmast3r17-Dec-04 22:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 11 Jul 2004
Article Copyright 2004 by Yulianto.
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid