Solved

multi-view in an sdi

Posted on 1997-11-19
5
436 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
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

860 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