CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2005
    Posts
    445

    Best way to toggle between views

    Hi all,

    I have a Dialog project and I am loading a form view inside a frame:

    Code:
    int CMyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        m_pFrame = (CFrameWnd*)RUNTIME_CLASS(CFrameWnd)->CreateObject();  
        m_pFrame->CreateEx(0, NULL, NULL, WS_CHILD, rc, this, AFX_IDW_PANE_FIRST, NULL); 
    
        CCreateContext ccc;
        ccc.m_pNewViewClass   = RUNTIME_CLASS(CHtmlView);
        ccc.m_pCurrentDoc     = NULL;
        ccc.m_pNewDocTemplate = NULL;
        ccc.m_pLastView       = NULL;
        ccc.m_pCurrentFrame   = NULL;
    			
        m_pMyFirstView = (CMyFirstView*)m_pFrame->CreateView(&ccc);
    Everything works fine and I can load the view with no problems.

    Now I want to toggle between two different views when a buttons is clicked.
    So I've extended the code to:

    Code:
    int CMyDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        m_pFrame = (CFrameWnd*)RUNTIME_CLASS(CFrameWnd)->CreateObject();  
        m_pFrame->CreateEx(0, NULL, NULL, WS_CHILD, rc, this, AFX_IDW_PANE_FIRST, NULL); 
    
        CCreateContext ccc;
        ccc.m_pNewViewClass   = RUNTIME_CLASS(CHtmlView);
        ccc.m_pCurrentDoc     = NULL;
        ccc.m_pNewDocTemplate = NULL;
        ccc.m_pLastView       = NULL;
        ccc.m_pCurrentFrame   = NULL;
    			
        m_pMyFirstView = (CMyFirstView*)m_pFrame->CreateView(&ccc);
    
        ccc.m_pNewViewClass   = RUNTIME_CLASS(CNoEmailViewForm);
        ccc.m_pCurrentDoc     = NULL;
        ccc.m_pNewDocTemplate = NULL;
        ccc.m_pLastView       = NULL;
        ccc.m_pCurrentFrame   = NULL;
    			
        m_pMySecondView = (CMySecondView*)m_pFrame->CreateView(&ccc);
    }
    
    void CMyDlg::OnBnClickedButton()
    {
        if (m_bFirst)
        {
            m_pMySecondView->ShowWindow(SW_SHOW);
            m_pMyFirstView ->ShowWindow(SW_HIDE);
            m_bFirst = FALSE;
        }
        else
        {
            m_pMySecondView->ShowWindow(SW_HIDE);
            m_pMyFirstView ->ShowWindow(SW_SHOW);
            m_bFirst = TRUE;
        }
    }
    This again works BUT I'm not sure if this is the correct way to do it.
    I have a feeling that I need to do something with m_pLastView (CCreateContext).

    Any advice?

    Thank you

    This again

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Best way to toggle between views

    Quote Originally Posted by Salvadoravi View Post
    Hi all,

    I have a Dialog project and I am loading a form view inside a frame:
    I stopped reading there. That sounds like a bad plan. While bucking the doc/view framework can be done, it isn't always easy and you should have a really good reason for doing it.

  3. #3
    Join Date
    Dec 2005
    Posts
    445

    Re: Best way to toggle between views

    Thanks GCDEF,

    I'll take a step back.

    The reason why I'm implementing it in the way I've described above is because I need to extend a fully mature dialog program that probably cannot be converted into a non dialog project (and if it somehow can I assume that it will take forever).

    My Goal:

    Code:
    ----------------------------------------------------------------
    | Existings Dialog with loads of custom controls                |
    |                                                               |
    |                                                               |
    ----------------------------------------------------------------
    |                                  |                            |
    |  [extensions] Adding a splitter  |                            |
    |                                  |                            |
    |      to load the views           |                            |
    |                                  |                            | 
    |                                  |                            |
    |           (CHTMLEditView)        |      (CHTMLView)           |
    |                                  |                            |
    |---------------------------------------------------------------
    Surprisingly it works fine.
    My next step is to add functionality to load a single view as described in my above question.

    Any advice will be appreciated!!

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Best way to toggle between views

    Quote Originally Posted by Salvadoravi View Post
    ... I need to extend a fully mature dialog program that probably cannot be converted into a non dialog project (and if it somehow can I assume that it will take forever).
    There is no any "dialog program" that cannot be converted into a non dialog project. Period.
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Best way to toggle between views

    After the "Period" I would add "With enough people, time and money."
    Best regards,
    Igor

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured