Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SDI: One Doc many views....

Posted on 1998-09-22
5
Medium Priority
?
181 Views
Last Modified: 2013-11-19
I know how to setup the MFC app. to handle one doc and a view for it.But, how do I support one doc. and X number of views for it ?

Or is it more efficient to have one doc, one view for it and let the view code render the data in different ways ?
0
Comment
Question by:migue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 1

Expert Comment

by:Bridge
ID: 1322417
Look at codguru
0
 
LVL 3

Accepted Solution

by:
plaroche earned 320 total points
ID: 1322418
In your CMainFrame save the CCreateContext (used to re-create more views)

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
      m_context = *pContext;

    return CFrameWnd::OnCreateClient(lpcs, pContext);
}

Then, after your document has been initialized and the original view has been created you can proceed to destroy that view, create the ones you want and position them where you want them.

Before destroying the default view make sure that your CDocument::m_bAutoDelete equals FALSE or the document will destroy itself when no more views are attached to it.

Creating the views can be done as follows:

pFiberView = new CFiberVisView;
pFiberView->Create( NULL, NULL, AFX_WS_DEFAULT_VIEW, rectDefault, this, AFX_IDW_PANE_FIRST, &m_context);

Notice the saved context being used here.

To create another view use the same Create call but add 1 to AFX_IDW_PANE_FIRST.

The rectDefault seen here may be empty since you will want to call MoveWindow on each view afterwards.

Then you need to call SetActiveView() on the view of your choice and also MANUALLY call OnInitialUpdate() on every view.  A call to RedrawWindow() after the OnInitialUpdate() might be needed.
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1322419
Incidentally MDI can be used for single doc multiple views (you need to add code to prevent creation of a second doc without closing the first one).  A reason to do this would be if you want tiling etc. menu options or the user to be able to size multiple views _independantly_ in both x and y dimensions
0
 

Author Comment

by:migue
ID: 1322420
to plaroche:

proposed solution looks good, but don't want to delete the default view, just add more views. Where do you propose to set(call SetActiveView) a particular view ? In other words, at what point of the code do I set a particular view ?

NOTE: bumped up the points.
0
 
LVL 3

Expert Comment

by:plaroche
ID: 1322421
In my project my views are created by posting a message from my CWinApp::InitInstance to my CMainFrame.  Doing that this way I am sure that my connection to the material is done and all my init code has been executed.

Having a bit more experience now I think I would have placed the view creation code in CMainFrame::OnCreate (handler of WM_CREATE).

So just save the context and from OnCreate call a function to create your other views.  When they are all created and moved to their correct place do a SetActiveView on the one you wish, your choice.

The user can also change operating mode from the app and it creates another view.  Doing this is then simple, just create the new view with the saved context and position it where it needs to go, making sure to resize the other views accordingly.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question