Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SDI: One Doc many views....

Posted on 1998-09-22
5
Medium Priority
?
184 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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.
Integration Management Part 2
Suggested Courses

886 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