Solved

SDI: One Doc many views....

Posted on 1998-09-22
5
174 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now