15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Multiple views in a splitter

Gordon J. Dodrill -- gjdodri@sandia.gov
Tuesday, May 21, 1996

Note: This may be a repeat.  I'm not sure if the last transmission was
      successful or ignored.


   VC++ 2.0 / Win 95 / SDI

How do I change the view in one pane of a static splitter window?

I have a static splitter window made up of 2 rows and 1 column with
different views in each pane.  I want to give the user the ability to
change the view in the bottom pane to any of five views.  The top 
view, different from the other five, will not change.  All six views
use the same CDocument derived object.

I have reviewed the code for CHKBOOK, but this example only shows how
to select different views as the only view in the frame window.

Gordon Dodrill




dobrin@itls.com
Tuesday, May 28, 1996

[Mini-digest: 3 responses]

Look in the MFC FAQ written by Scott Wingo, at : 
http://www.unx.com/~scot/mfc_faq.htm.

Regards,

Dan Dobrin
dan.dobrin@itls.com

-----From: "Frederic Steppe" 

I guess you should just call DeleteView to remove the old view, and then 
CreateView to add the new one.
You may get the old view size and give it to CreateView as the initial size of 
the new view, to keep the splitter at the same position.


Frederic Steppe (frederics@msn.com)
-----From: Gordon Weakliem 

I've done the same thing in an MDI application. Basically, I started with
this sample code from the help on CDocument::AddView:

// The following example toggles two views in an SDI (single document
// interface) frame window.  A design decision must be made as to
// whether to leave the inactive view connected to the document,
// such that the inactive view continues to receive OnUpdate
// notifications from the document.  It is usually desirable to
// keep the inactive view continuously in sync with the document, even 
// though it is inactive.  However, doing so incurs a performance cost,
// as well as the programming cost of implementing OnUpdate hints.
// It may be less expensive, in terms of performance and/or programming,
// to re-sync the inactive view with the document only with it is 
// reactivated.  This example illustrates this latter approach, by 
// reconnecting the newly active view and disconnecting the newly 
// inactive view, via calls to CDocument::AddView and RemoveView.

BOOL CMainFrame::OnViewChange(UINT nCmdID)
{
   CView* pViewAdd;
   CView* pViewRemove;
   CDocument* pDoc = GetActiveDocument();
   if (nCmdID == ID_VIEW_VIEW2)
   {
      if (m_pView2 == NULL)
      {
         m_pView1 = GetActiveView();
         m_pView2 = new CMyView2;
         m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
            rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);
      }
      pViewAdd = m_pView2;
      pViewRemove = m_pView1;
   }
   else
   {
      pViewAdd = m_pView1;
      pViewRemove = m_pView2;
   }

   // Set the child i.d. of the active view to AFX_IDW_PANE_FIRST,
   // so that CFrameWnd::RecalcLayout will allocate to this 
   // "first pane" that portion of   the frame window's client area 
   // not allocated to control   bars.  Set the child i.d. of the 
   // other view to anything other than AFX_IDW_PANE_FIRST; this
   // examples switches the child id's of the two views.

   int nSwitchChildID = pViewAdd->GetDlgCtrlID();
   pViewAdd->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
   pViewRemove->SetDlgCtrlID(nSwitchID);
     // Show the newly active view and hide the inactive view.
   pViewAdd->ShowWindow(SW_SHOW);
   pViewRemove->ShowWindow(SW_HIDE);

   // Connect the newly active view to the document, and
   // disconnect the inactive view.
   pDoc->AddView(pViewAdd);
   pDoc->RemoveView(pViewRemove);

   // Inform the frame window which view is now active;
   // and reallocate the frame window's client area to the
   // new view. Implement logic to resync the view to the
   // document in an override of CView::OnActivateView,
   // which is called from CFrameWnd::SetActiveView. 
   SetActiveView(pViewAdd);
   RecalcLayout();

   return TRUE;
 }

What I do in my version of OnViewChange is to create a CRuntimeClass for the
view I'd like to create, and then use that CRuntimeClass as an argument to
CSplitterWnd::CreateView.  Although the docs make it sound like you can't
call CreateView once the splitter's created, I haven't had any problems with
this.

hope this helps
Gordon Weakliem
gweakl@metronet.com





| Вернуться в корень Архива |