Solved

SDI: One Doc many views....

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how do i create updater to My Activex application? 3 102
zeroMAx challenge 20 127
FizzBuzz challenge 9 86
Work with App store 7 96
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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