Solved

multi-view in an sdi

Posted on 1997-11-19
5
444 Views
Last Modified: 2010-08-05
I have 4 daorecordviews set up in the init of the app
ex : m_mydoctemp[0] =
CmultiDocTemplate = {menu, doc1, mainframe, view1)
adddoctemp ...
m_mydoctemp[1] =
CmultiDocTemplate = {menu, doc2, mainframe, view2)
adddoctemp ...
the app is designed as a SDI. I want to be able to show different views with there document data when a menu selection is choosen.
Replace one view with the other.  Where do I go from here?
0
Comment
Question by:sas110397
[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
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 100 total points
ID: 1173632
Basically, you will need to write a function in the mainframe to do this:

 CMainFrame::SwitchToView(int view)
 {
   CView* oldView = GetActiveView();
   CView* newView = NULL;
   switch (view)
   {
     case view1:
       newView = new CView1;
       break;
     case view2:
       newView = new CView2;
       break;
   }

   CCreateContext context;

   // Set up document. This assumes current doc. But if you have
   // new document, then you can create it here
   context.m_pCurrentDoc = pOldView->GetDocument();
   newView->Create(NULL, NULL, 0L, CFrameWnd::rectDefault, this, view, &context);
   newView->OnInitialUpdate();
   SetActiveView(newView);
   newView->ShowWindow(SW_SHOW);
   oldView->ShowWindow(SW_HIDE);
   RecalcLayout();
 }
0
 

Author Comment

by:sas110397
ID: 1173633
I think this the right way to go.  However, I tried this last night and Kept recieving an access violation when trying to Create.  I did change the templates back to CSingleDocTemplate,  the Frame is based on CFrameWin.  I had to change the menu resorce in three of the templates to force the NEW window to stop displaying on startup.  I tried changing the sting resource to achieve this but could not get it to start with the first template.  The views and documents I'm trying to create and open are based off of the DAO database classes.
0
 

Expert Comment

by:sreejesh
ID: 1173634
Dear thui, You had given a very good explanation for SDI.But I am asking the same question for MDI.ie., How can I associate a each document to each view (One document for one view). I Expect the very best answer from you !.
0
 

Author Comment

by:sas110397
ID: 1173635
You must make up a document for each view and create a document template for each pair in the init functuion of your app.
Once this is done you can make a call in your program to change the template thus change the view and document pointer.  I don't have the exact code with me right now.  But that's the jist of it.  The templates must be based off of CMultiDocTemplate.
0
 

Expert Comment

by:sreejesh
ID: 1173636
Yes Sas.As you said , I made a document template for the view in the app. But I didn't get which call is to be placed in my program to change the template to change the view and document pointer. Also please let me know where I can call that !.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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