⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splittertabwnd.cpp

📁 Visual C++下的界面设计
💻 CPP
字号:
/*
   FILNAME:       splitterTabWnd.cpp

   PURPOSE:       Manage view's that you can switch between by clicking at the tab.

   CREATED BY:    Per Ghosh
   ENVIRONMENT:	Visual C++


INFO:
*/

#include "stdafx.h"
#include "tab.h"

#include "TabView.h"

#include "splitterTabWnd.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


IMPLEMENT_DYNCREATE(CsplitterTabWnd, CSplitterWnd)

/************************************************
   *   Constructor/Destructor 
   *
 * * *
  ***
   *
*/

CsplitterTabWnd::CsplitterTabWnd() :
   m_pwndTab(NULL), m_uSelectedViewIndex(0)
{
   m_cxSplitter    = m_cySplitter    = 0;   // size of splitter bar
   m_cxSplitterGap = m_cySplitterGap = 0;   // amount of space between panes
   m_cxBorder      = m_cyBorder      = 0;   // borders in client area
}

CsplitterTabWnd::~CsplitterTabWnd()
{
   if( m_pwndTab ) delete m_pwndTab;
}

/************************************************
   *   Virtual functions
   *
 * * *
  ***
   *
*/
/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:

Return:
*/
void CsplitterTabWnd::RecalcLayout()
{
   CWnd* pWnd;
   CRect rectClient;

   HDWP hdwp;

   GetClientRect( rectClient );

   // Set position for the tab window
   pWnd = GetPane( 1, 0 );

   hdwp = ::BeginDeferWindowPos( 2 );

   DeferWindowPos( hdwp,
                   pWnd->m_hWnd,
                   NULL,
                   rectClient.left,
                   rectClient.bottom - m_pwndTab->GetHeight(),
                   rectClient.right,
                   m_pwndTab->GetHeight(),
                   SWP_NOACTIVATE|SWP_NOZORDER );

   // Set position for the working-window
   pWnd = GetPane( 0, 0 );
   DeferWindowPos( hdwp,
                   pWnd->m_hWnd,
                   NULL,
                   rectClient.left,
                   rectClient.top,
                   rectClient.right,
                   rectClient.bottom - m_pwndTab->GetHeight(), 
                   SWP_NOACTIVATE|SWP_NOZORDER );

   EndDeferWindowPos( hdwp );

}

/************************************************
   *   Functions 
   *
 * * *
  ***
   *
*/
/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:

Return:
*/
BOOL CsplitterTabWnd::Create( CWnd* pwndParent, CCreateContext* pContext )
{
   ASSERT( m_ptrarrayRCView.GetSize() );         // must be one or more
   ASSERT( pwndParent->IsKindOf( RUNTIME_CLASS( CFrameWnd ) ) );

   CRuntimeClass* pRCView;                       // runtime class for first working view

   SIZE  size;                                   // 
   CRect rect;                                   //

   pRCView = (CRuntimeClass*)m_ptrarrayRCView[0];
   ASSERT( pRCView->IsDerivedFrom( RUNTIME_CLASS( CWnd ) ) );

   CreateStatic( pwndParent, 2, 1, WS_CHILD );   // create two panes

   pwndParent->GetClientRect( &rect );           // get rect for frame window
   
   size.cx = rect.right;
   size.cy = rect.bottom - 20;
   
   VERIFY( CreateView( 0, 0, pRCView, size, pContext ) );

   size.cy = 20;
   VERIFY( CreateView( 1, 0, RUNTIME_CLASS(CwndTab), size, pContext ) );

   m_pwndTab = (CwndTab*)GetPane( 1, 0 );
   m_pwndTab->SetSplitterTabWnd( this );
   
   ShowWindow( SW_SHOWNORMAL );
   UpdateWindow();

   return TRUE;

}

/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:

Return:
*/
UINT CsplitterTabWnd::AddView( CRuntimeClass* pRCView, LPCTSTR pszViewName )
{
   ASSERT( pRCView->IsDerivedFrom( RUNTIME_CLASS( CWnd ) ) );
   m_ptrarrayRCView.Add( pRCView );
   m_sarrayViewName.Add( pszViewName );

   if( m_pwndTab ) m_pwndTab->SetModified();

   return m_ptrarrayRCView.GetSize();
}

/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:
*/
void CsplitterTabWnd::InsertView( UINT uIndex, CRuntimeClass* pRCView, LPCTSTR pszViewName )
{
   ASSERT( pRCView->IsDerivedFrom( RUNTIME_CLASS( CWnd ) ) );
   ASSERT( uIndex < 100 );                                 // Realistic
   ASSERT( uIndex < (UINT)m_ptrarrayRCView.GetSize() );

   if( uIndex <= m_uSelectedViewIndex ) m_uSelectedViewIndex++;

   m_ptrarrayRCView.InsertAt( (int)uIndex, pRCView );
   m_sarrayViewName.InsertAt( (int)uIndex, pszViewName );

   if( m_pwndTab ) m_pwndTab->SetModified();
}

/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:
*/
void CsplitterTabWnd::SelectView( UINT uIndex )
{
   ASSERT( uIndex < (UINT)m_ptrarrayRCView.GetSize() );

   ReplaceView( (CRuntimeClass*)m_ptrarrayRCView[uIndex] );
   m_uSelectedViewIndex = uIndex;

   if( m_pwndTab ) m_pwndTab->Invalidate();
}

/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:
*/
void CsplitterTabWnd::RemoveView( CRuntimeClass* pRCView )
{
   int iIndex;
   CRuntimeClass* pRCViewInList;

   iIndex = m_ptrarrayRCView.GetSize();

   while( iIndex )
   {
      pRCViewInList = (CRuntimeClass*)m_ptrarrayRCView[iIndex];
      if( pRCViewInList == pRCView )
      {
         ASSERT( m_uSelectedViewIndex != (UINT)iIndex );
         m_ptrarrayRCView.RemoveAt( iIndex );

         if( m_pwndTab )
         {
            m_pwndTab->SetModified();
            m_pwndTab->Invalidate();
         }// endif
      }// endif
   }// endwhile

   TRACE1("CsplitterTabWnd::RemoveView()\nWarning: Did not find %s\n", pRCView->m_lpszClassName );
}

/*-------------------------------------------------------------------------------------------------
Name:	 
Type:    
Purpose: 

Param:
*/
void CsplitterTabWnd::RemoveView( UINT uIndex )
{
   ASSERT( uIndex < 100 );                                 // Realistic
   ASSERT( uIndex < (UINT)m_ptrarrayRCView.GetSize() );
   ASSERT( m_uSelectedViewIndex != uIndex );

   m_ptrarrayRCView.RemoveAt( (int)uIndex );

   if( m_pwndTab )
   {
      m_pwndTab->SetModified();
      m_pwndTab->Invalidate();
   }
}



/*-------------------------------------------------------------------------------------------------
Name:    ReplaceView()
Type:    Function
Purpose: Destroy current working view and creates a new

 Param:  pViewClass = Pekare till CRuntimeClass'en f鰎 den view som vi skall skapa
 Info:
 Med denna funktion tar vi och byter den view som finns i huvudf鰊stret. Den view som tidigare
 d鋜 raderas vilket ocks

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -