Adding a another View/Frame to a document
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Adding a another View/Frame to a document

  1. #1
    Join Date
    Aug 2006
    Posts
    508

    Adding a another View/Frame to a document

    My document has multiple views. I am adding another view whose frame class is different and it initial size comes up to zero (just the title bar of the window shows up).
    Code:
            CChildFrame* pNewFrame = (CChildFrame*) theApp.m_pMyDocTemplate->CreateNewFrame( pDoc, pFrame );
    
            // create new view
            if (pNewFrame != NULL )
                pNewFrame->InitialUpdateFrame(pDoc, TRUE);
    I have other views added too and they work fine. I know the difference is that these other views have the same CFrameWnd in the CMultiDocTemplate but this new view has a difference frame class
    Code:
    m_pTestDocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildFrame), 
            RUNTIME_CLASS(CTestView));
        AddDocTemplate(m_pTestDocTemplate);
    
    m_pTest2DocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildFrame), 
            RUNTIME_CLASS(CTest2View));
        AddDocTemplate(m_pTest2DocTemplate);
    
    m_pTest3DocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildCustomFrame), // custom MDI child frame
            RUNTIME_CLASS(CTest3View));
        AddDocTemplate(m_pTestDocTemplate);
    As you can see from the definitions, when I add m_pTest2DocTemplate it works fine because the CChildFrame is the same but adding m_pTest3DocTemplate starts the new view in zero size perhaps because of different frame class?

    What is the strategy to add the view if their is a different frame class involved as well? The custom frame class that I am using controls the sizing requirements of the view in my case.

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Adding a another View/Frame to a document

    Hi,

    Can you tell us a little bit more about the error you get? Is there a compile time error or a runtime error (Assertion possibly?)?

    If you get an assertion step into the MFC code. Often you'll see what happened and why the assertion came up.

    With regards
    Programartist

  3. #3
    Join Date
    Jun 2006
    Posts
    644

    Re: Adding a another View/Frame to a document

    What the heck...I hope you have mistyped the code here...or else...
    Code:
    m_pTestDocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildFrame), 
            RUNTIME_CLASS(CTestView));
        AddDocTemplate(m_pTestDocTemplate);
    
    m_pTest2DocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildFrame), 
            RUNTIME_CLASS(CTest2View));
        AddDocTemplate(m_pTest2DocTemplate);
    
    m_pTest3DocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildCustomFrame), // custom MDI child frame
            RUNTIME_CLASS(CTest3View));
        AddDocTemplate(m_pTestDocTemplate);
    Did u find the error yet? In the third doc template, u r adding the reference to the first doc template. I believe this is the error...
    Just change m_pTestDocTemplate in 3rd case to m_pTest3DocTemplate...

    Regards,
    Bhushan

  4. #4
    Join Date
    Aug 2006
    Posts
    508

    Re: Adding a another View/Frame to a document

    Quote Originally Posted by bhushan1980 View Post
    What the heck...I hope you have mistyped the code here...or else...
    Sorry about it but it is just a typo in the post. I simply renamed the variable names.

    I don't get any compiler error. The problem is just that the new view/frame shows in zero size, it's only the title bar you see. I can than resize the window to make it bigger but initital size is just the smallest possible.

    My suspiction is confirmed though, if I change the frame class to match it to the rest of the group, my window shows up in proper size.
    Code:
    m_pTest3DocTemplate = new CMultiDocTemplate(
            IDR_MAINFRAME, 
            RUNTIME_CLASS(CTestDoc),
            RUNTIME_CLASS(CChildFrame), // CChildCustomFrame
            RUNTIME_CLASS(CTest3View));
        AddDocTemplate(m_pTest3DocTemplate)
    
    But I want to be able to use a new frame class with the new view, how can I do that?

  5. #5
    Join Date
    Aug 2006
    Posts
    508

    Re: Adding a another View/Frame to a document

    I found the mistake. It was not the fact that it was a different frame. The frame is getting resized to an image displayed in the view but when view is created, the image is not initialized yet - is zero so window size is zero.

    I am displaying this image from the document. First I am creating new view/frame and than you use UpdateAllViews() to pass the view to display the image.

    The problem is that my frame needs to be adjusted to the image size so I would really like to have access to the image when frame is created. Is there a way I can pass the image to the view at the time of creation?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center