Solved

multi-view in an sdi

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

706 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

15 Experts available now in Live!

Get 1:1 Help Now