CDocument::AddView

void AddView ( CView * pView );

¸Å°³ º¯¼ö

pView

Ãß°¡ µÇ´Â ºä Æ÷ÀÎÆ®¡£

ÁÖÀÇ

º¸±â¸¦ ¹®¼­¿¡ ÷ºÎ ÇÏ·Á¸éÀÌ ÇÔ¼ö¸¦ È£Ãâ ÇÕ´Ï´Ù. ºä´Â ¹®¼­¿Í ¿¬°á µÈ ¸ñ·Ï¿¡ ÁöÁ¤ µÈ º¸±â¸¦ Ãß°¡ ÇÏ´ÂÀÌ ÇÔ¼ö ÇÔ¼ö´Â ¶ÇÇÑÀÌ ¹®¼­¿¡ º¸±âÀÇ ¹®¼­ Æ÷ÀÎÅ͸¦ ¼³Á¤ÇÕ´Ï´Ù. ¹®¼­; »õ·Î ¸¸µçµÈ view °³Ã¼¸¦ ¿¬°áÇÒ ¶§ÀÌ ÇÔ¼ö¸¦ È£Ãâ ÇÏ´Â ÇÁ·¹ÀÓ ¿öÅ© ÀÌ ÀÀ´ä »õ ÆÄÀÏ, ÆÄÀÏ ¿­±â ¶Ç´Â »õ â ¸í·É ¶Ç´Â ºÐÇÒ Ã¢ÀÌ ºÐÇÒ ÇÏ´Â °æ¿ì¿¡ ¹ß»ý ÇÕ´Ï´Ù.

¼öµ¿À¸·Î ¸¸µé°í ºä¸¦ ¿¬°á ÇÏ´Â °æ¿ì¿¡ÀÌ ÇÔ¼ö¸¦ È£Ãâ ÇÕ´Ï´Ù. ÀϹÝÀûÀ¸·Î ¹®¼­ Ŭ·¡½º, ºä Ŭ·¡½º¿Í ÇÁ·¹ÀÓ Ã¢ Ŭ·¡½º¸¦ ¿¬°áÇÒ CDocTemplate °³Ã¼¸¦ Á¤ÀÇ ÇÏ ¿© ¹®¼­ ¹× ºä¸¦ ¿¬°á ÇÏ´Â ÇÁ·¹ÀÓ ¿öÅ©¸¦ ¾Ë·Áµå¸³´Ï´Ù.

¿¹Á¦

// 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();
 UINT nCmdID;
    
 nCmdID = LOWORD(GetCurrentMessage()->wParam);
   
 if((nCmdID == ID_VIEW_VIEW1) && (m_currentView == 1))
    return;
 if((nCmdID == ID_VIEW_VIEW2) && (m_currentView == 2))
   return;

 if (nCmdID == ID_VIEW_VIEW2)
 {
  if (m_pView2 == NULL)
  {
   m_pView1 = GetActiveView();
   m_pView2 = new CMyView2;

//Note that if OnSize has been overridden in CMyView2 
//and GetDocument() is used in this override it can 
//cause assertions and, if the assertions are ignored,
//cause access violation.
  
   m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
      rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL);
  }
   pViewAdd = m_pView2;
   pViewRemove = m_pView1;
   m_currentView= 2;
 }
 else
 {
  pViewAdd = m_pView1;
  pViewRemove = m_pView2;
  m_currentView= 1;
 }
     
// 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(nSwitchChildID);

 // 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);

 SetActiveView(pViewAdd);
 RecalcLayout();
}

CDocument °³¿ä |nbsp; Ŭ·¡½º ¸â¹ö (ko) | °èÃþ ±¸Á¶ Â÷Æ®(&N)

Âü°í Ç׸ñnbsp;CDocTemplate, CDocument::GetFirstViewPosition, CDocument::GetNextView, CDocument::RemoveView, CView::GetDocument(&N)

Index