Solved

SDI: One Doc many views....

Posted on 1998-09-22
5
177 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
5 Comments
 
LVL 1

Expert Comment

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

Accepted Solution

by:
plaroche earned 80 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to know only "File created" with EventLog 3 35
sumDigits challenge 9 170
Not needed 13 119
I could not set window to top 4 20
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

809 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