Multiple Views for a Single Document (MDI)

I add here the code that could be used to add multiple views to a document, in a MDI application. I usually make database applications, and I don't want that the document to be created/destroyed by the framework, so I create the document myself (and of course I destroy it J ), and in document's constructor I set the m_bAutoDelete flag to FALSE.

The CMyApp class contains as public member a pointer to my document. I also make document templates for all views, and I keep the pointers in CMyApp. You should have something like this in InitInstance():

m_pView1Templ=new CMultiDocTemplate( IDR_VIEW1TYPE,
RUNTIME_CLASS( CMyDoc ),
RUNTIME_CLASS( CChildFrame ),
RUNTIME_CLASS( CView1 ) );
AddDocTemplate(m_pView1Templ);
// m_pView1Templ is member of CMyApp

After you created all necessary document templates, add the following code:

// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
mp_doc=new CTimeClkDoc;
mp_doc->SetTitle("Just a demo");
CCreateContext context;
context.m_pCurrentDoc=mp_doc;
context.m_pNewViewClass=NULL;
context.m_pNewDocTemplate=NULL;
context.m_pLastView=NULL;
context.m_pCurrentFrame=NULL;
if (!pMainFrame->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW |
                           FWS_ADDTOTITLE,NULL, &context ))
   return FALSE;
m_pMainWnd = pMainFrame;

This code will allow opening the application without any open view and also avoids the dialog box that asks to choose a document template. Add for each view command handlers similar with this one:

void CMyApp::OnView1()
{
   // TODO: Add your command handler code here
   CChildFrame* pFrame = new CChildFrame();
   CCreateContext context;
   context.m_pCurrentDoc=mp_doc;    //that's the way I avoid creating
                                    //a new document every time I open
                                    //a new view
   context.m_pNewViewClass=RUNTIME_CLASS(CView1);
   context.m_pNewDocTemplate=m_pView1Templ;
   context.m_pLastView=(((CMainFrame *)m_pMainWnd)->
                        GetActiveFrame() ? ((CMainFrame *)m_pMainWnd)->
                        GetActiveFrame()->GetActiveView() : NULL);
   context.m_pCurrentFrame=((CMainFrame *)m_pMainWnd)->GetActiveFrame();
   if (!pFrame->LoadFrame(IDR_VIEW1TYPE,WS_OVERLAPPEDWINDOW |
                          FWS_PREFIXTITLE ,m_pMainWnd, &context ))return;
   pFrame->InitialUpdateFrame(mp_doc,TRUE);
}


Comments

  • effekten er en smuk hovedtelefoner

    Posted by drkczp702 on 07/17/2013 02:58pm

    Som en atlet de ‘træning, som’, jeg gør, hvad jeg skal gøre for at blive klar “kan hovedtelefonen hjælper mig til at føle jeg er så meget tættere på min musik, der hjælper mig udføre, hjælper mig med at finde ud af, om jeg vil at være intens? Uanset hvad jeg ønsker at være på banen den dag, musik hjælper mig derhen. Da de sagde ja, vil produktet blive valgt og hjælpe dem med at opretholde den bedste tilstand I spillet.Ifølge en talsmand for selskabet, ved Dre endnu ikke har haft en dialog med IOC om “ambush marketing” praksis af atleter iført og twitte om de sanktioneret hovedtelefoner Beats. Men Omar Johnson, Beats senior VP for markedsføring, fortæller Billboard.biz at virksomheden arbejder med atleter året rundt. [url=http://beatsbydretilbud.webspawner.com/]beats by dre[/url] Mange musikelskere tror, Musik er noget, der flyder gennem nerverne, som er bogstaveligt talt sandt, trods alt, føler det samme, da de mener. Så hvis du er til musik på en seriøs måde, så hvordan du foretrækker at flyde igennem det? Nå, jeg tror den bedste lydkvalitet ville være dit første præferencer for at øge smagen af din yndlingsmusik. Nå, mange tror musik er den del af livet, så mener jeg det samme. Det er noget, svært at forklare, men det eneste, du kan gøre med det, er føler. Derfor, dette er hvad alt hvad du behøver, det fedeste og kvalitet dr. dre Horetelefoner til at føle det bedre. [url=http://beatsbydretilbud.webspawner.com/]beats by dre[/url] Hestekræfter samt reggae hele verden har kombineret såvel som resultatet er den nye Doctor Dre laptop. Med ferier her og også Dr. Dre laptop annoncer viser konstant på tv, er alle spekulerer på, om de skal købe det faktiske H. s.. Misundelse (den bestemte specialiserede navn med den personlige computer).Over-the-ear hovedtelefoner er fantastisk for ejendom bliver opmærksomme samt vejledning i at lukke ud lyde som du sover. On-ear typer bør også være behageligt, sammen med delikat ekstra polstring og robust konstruktion. Bare om de mest væsentlige ting sammen med on-ear design er at sikre, at de er installeret til brug sammen med stikkene i dine gadgets.

    Reply
  • how to create child window within child windows

    Posted by yogesh28577 on 03/28/2006 01:25am

    suppose i create abc child windows & xyz child windows but it parent is abc xyz look like child of abc plz help me yogesh shrikhande yogesh28577@yahoo.co.in

    Reply
  • Way easier way to do this

    Posted by Legacy on 08/17/2003 12:00am

    Originally posted by: Martin Chapman

    Override OnFileNew() in your App class like:
    
    

    afx_msg void OnFileNew();

    Add mesage_macro and implementation to cpp file like:

    ON_COMMAND(ID_FILE_NEW, OnFileNew)
    ...
    void CViewPortApp::OnFileNew()
    {
    }

    when you want a new doc just call:

    AfxGetApp()->m_pDocManager->OnFileNew();

    from anywhere in your app!!!

    Reply
  • How to close old View

    Posted by Legacy on 04/09/2002 12:00am

    Originally posted by: Narendra Jain

    When I switch view, I want to close the old active view without destroying the Document. Please tell me how can I do it?

    Reply
  • child window clean properly?

    Posted by Legacy on 02/10/2002 12:00am

    Originally posted by: yann

    hi! i've tried your code, it works..... one time!!!!
    So, when i run my application, i can open the child window, then i close it. then, whithout quit the application, i tried to open the child window a new time, and VC++ tell me about an assertion failed.....

    What's wrong ?

    Thank's, Yann.

    Reply
  • problem w/ code

    Posted by Legacy on 12/13/2001 12:00am

    Originally posted by: Mike

    I used this code and have one problem. When the view is opened up, there is a flickering on the screen. It is happening after the call to pFrame->LoadForm(). This call is creating the child frame at the wrong size and the pFrame->InitialUpdateFrame() resizes the view to the correct size. Is there a way to prevent this flickering from occuring?

    Reply
  • What is the truetype font or vector font file format?

    Posted by Legacy on 09/19/2001 12:00am

    Originally posted by: jiangli

    Dear sir:
    
    What is the truetype font or vector font file format?
    I wish you to tell me in a short time.
    Thank you.

    Reply
  • How to create the different views

    Posted by Legacy on 03/03/2000 12:00am

    Originally posted by: Ehtesham Siddiqui

    *URGENT*
    
    

    When attaching multiple views to a Document in an MDI Application we need two or more different "views" derived from the "CView" class to do so.... By default in App Wizard one view say "MyView" is created.

    How can we create one or more additional views to add to the application...I created a copy of the origional view of the Application and reproduced "Resourse Strings" for it manually and added them to the "Strings Resourse" and then created a new Document-Template for it but it didn't work....... it gives an *Assertion Failed* at Run-Time when it executes the statement

    <ccode>
    if (!pFrame->LoadFrame(IDR_ASYSTEM2TYPE,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,m_pMainWnd, &context ))return;
    pFrame->InitialUpdateFrame(mp_doc,TRUE);
    </ccode>

    in the member function of Application class
    "CMyApp::OnView2()"
    (The purpose of which is to create an instance of the second *newer* view)

    Please help me ..... Thanks in advance!!!

    Ehtesham Siddiqui.

    Reply
  • Please add project files

    Posted by Legacy on 12/27/1999 12:00am

    Originally posted by: Mark Zarzour

    Please add project files.

    Reply
  • Setting window title for views

    Posted by Legacy on 10/08/1999 12:00am

    Originally posted by: DD

    Using the above I can create multiple views successfully. However, all my views have the same title, in this case "Just a demo". I would like each of my views to have a user provided title. I tried doing "SetWindowText(" XXX") " in the OnInitialUpdate() but it doesnt work. I tried the following:
    void CSomeView::OnPaint()
    {

    CPaintDC dc(this); // device context for painting

    CMainFrame* pFrame;
    VERIFY( pFrame = (CMainFrame*)GetParentFrame() );
    pFrame->SetWindowText("What ever the title is");

    }
    This works but with multiple windows open the painting sometimes does not refresh window titles correctly.

    Is there a better way to set the window title?

    Thanks


    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 23, 2014 @ 12:00 p.m. ET / 9:00 a.m. PT Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this eSeminar to learn why physical appliances are preferable to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds