does CTabbedMDI supports shared page view?

Ivan.Zhang
2011-01-04
2013-05-28
  • Ivan.Zhang

    Ivan.Zhang - 2011-01-04

    Hi, David,
    From the TabbedMDI sample, I noticed that a new view will be created for each tab page:
    AddMDIChild(new xxxx, …)

    Can I use a same view for all tab pages like this:
    create a page view at first:
    CMyEditView* pview = new CMyEditView;
    then I will invoke AddMDIChild(pview , …) for each new tab;
    when switching tab, my class CMyEditView will take charge of loading the correct document;
    and pview won't be deleted and its window won't be destroyed when a tab is closed;
    unless all tabs are closed or my program exits.

    Thank you.

     
  • David

    David - 2011-01-05

    Hi,

    By default TabbedMDIs will expect to destroy the view window and call delete on the view's CWnd pointer when tab is removed. You could alter this by modfying or overriding CTab::AddTabPage and CTab::RemoveTabPage appropriately.

    When a new tab page is added, CTab::AddTabPage converts the view window pointer to a smart pointer and stores it in the m_vTabViews vector. CTab::RemoveTabPage destroys the view window and removes the smart pointer from the m_vTabViews vector (thereby calling the view CWnd's destructor).

    This (untested) approach should do what you want…
    1) modify CTab::AddTabPage and to stop the pointer from being converted to a smart pointer, and skip the part where the smart pointer is added to the m_vTabsView vector.
    2) modify CTab::RemoveTabPage and skip the part where the view window is destroyed.
    It would then be your responsibility to ensure that delete is called on the CMyEditView pointer to avoid a memory leak, perhaps in the destructor of CMainFrame.

    Best regards,
    David

     
  • Ivan.Zhang

    Ivan.Zhang - 2011-01-05

    Hi, David,
    thank you very much :)

     

Log in to post a comment.