TabWnd.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:6k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // TabWnd.cpp : implementation file
- //
- #include "stdafx.h"
- #include "TabWnd.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define TAB_HEIGHT 22
- #pragma comment( lib , "msimg32.lib" )
- /////////////////////////////////////////////////////////////////////////////
- // CTabWnd
- CTabWnd::CTabWnd()
- {
- this->OnTab = NULL;
- this->pContext = NULL;
- }
- CTabWnd::~CTabWnd()
- {
- }
- BEGIN_MESSAGE_MAP(CTabWnd, CTabCtrl)
- //{{AFX_MSG_MAP(CTabWnd)
- ON_WM_DESTROY()
- ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
- ON_NOTIFY_REFLECT(TCN_SELCHANGING, OnSelchanging)
- ON_WM_SIZE()
- ON_WM_CREATE()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_PAINT()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTabWnd message handlers
- void CTabWnd::PreSubclassWindow()
- {
- this->SetFont( this->GetParent( )->GetFont( ) );
- CTabCtrl::PreSubclassWindow();
- }
- int CTabWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CTabCtrl::OnCreate(lpCreateStruct) == -1)
- return -1;
- this->SetFont( this->GetParent( )->GetFont( ) );
- return 0;
- }
- void CTabWnd::RegisterTabChangeEvent( void ( * OnTab )( void * pContext , int index , bool m_bShow ) , void * pContext )
- {
- this->OnTab = OnTab;
- this->pContext = pContext;
- }
- bool CTabWnd::AddTab( LPCSTR name )
- {
- if( name && strlen( name ) )
- return this->InsertItem( this->GetItemCount( ) , name );
- return false;
- }
- bool CTabWnd::AddWnd( CWnd * pWnd , LPCSTR name , bool autoDelete )
- {
- ASSERT( pWnd != NULL );
- if( ! ::IsWindow( pWnd->GetSafeHwnd( ) ) ) return false;
- pWnd->SetParent( this );
- // pWnd->ModifyStyle( WS_CAPTION | WS_BORDER | WS_THICKFRAME , 0 );
- // pWnd->ShowWindow( SW_MAXIMIZE );
- CRect rc;
- this->GetClientRect( &rc );
- pWnd->MoveWindow( rc );
- CString szName;
- if( name )
- szName = name;
- else
- pWnd->GetWindowText( szName );
- pWnd->ShowWindow( ! this->InsertItem( TCIF_TEXT | TCIF_PARAM , this->GetItemCount( ) , szName , 0 , ( int )pWnd ) ? SW_SHOW : SW_HIDE );
- ::SetWindowLong( pWnd->GetSafeHwnd( ) , GWL_USERDATA , autoDelete );
- this->ShowWindow( SW_SHOW );
- return true;
- }
- void CTabWnd::OnDestroy()
- {
- for( int i = 0; i < this->GetItemCount( ) ; i ++ )
- {
- try
- {
- CWnd * pWnd = this->GetWnd( i );
- if( pWnd )
- {
- bool del = ( bool )::GetWindowLong( pWnd->GetSafeHwnd( ) , GWL_USERDATA );
- pWnd->DestroyWindow( );
- if( del )
- delete pWnd;
- }
- }
- catch( ... )
- {
- }
- }
- CTabCtrl::OnDestroy();
- }
- CWnd * CTabWnd::GetWnd( int index )
- {
- TCITEM item;
- item.mask = TCIF_PARAM ;
- if( index == -1 )
- index = this->GetCurSel( );
- this->GetItem( index , &item );
- return ( CWnd * )item.lParam;
- }
- void CTabWnd::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CWnd * pWnd = this->GetWnd( );
- if( pWnd )
- pWnd->ShowWindow( SW_HIDE );
- if( this->OnTab )
- this->OnTab( this->pContext , this->GetCurSel( ) , false );
- if( pResult )
- *pResult = 0;
- }
- void CTabWnd::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
- {
- CWnd * pWnd = this->GetWnd( );
- if( pWnd )
- pWnd->ShowWindow( SW_SHOW );
- if( this->OnTab )
- this->OnTab( this->pContext , this->GetCurSel( ) , true );
- if( pResult )
- *pResult = 0;
- this->Invalidate( );
- }
- int CTabWnd::SetCurSel( int nItem )
- {
- if( this->GetSafeHwnd( ) )
- {
- this->OnSelchanging( 0 , 0 );
- int ret = CTabCtrl::SetCurSel( nItem );
- this->OnSelchange( 0 , 0 );
- return ret;
- }
- return -1;
- }
- void CTabWnd::GetClientRect( LPRECT lpRect )
- {
- CTabCtrl::GetClientRect( lpRect );
- lpRect->bottom -= TAB_HEIGHT;
- }
- BOOL CTabWnd::OnCommand(WPARAM wParam, LPARAM lParam)
- {
- if( this->GetParent( ) )
- return this->GetParent( )->SendMessage( WM_COMMAND , wParam , lParam );
- return CTabCtrl::OnCommand( wParam, lParam );
- }
- void CTabWnd::OnSize(UINT nType, int cx, int cy)
- {
- CTabCtrl::OnSize(nType, cx, cy);
- for( int i = 0; i < this->GetItemCount( ) ; i ++ )
- {
- CWnd * pWnd = this->GetWnd( i );
- if( pWnd )
- pWnd->MoveWindow( 0 , 0 , cx , cy - TAB_HEIGHT );
- }
- }
- void CTabWnd::OnLButtonDblClk( UINT nFlags, CPoint point )
- {
- TCHITTESTINFO info;
- info.pt = point;
- info.flags = TCHT_ONITEM;
- int index = this->HitTest( &info );
- if( index >= 0 )
- {
- CWnd * wnd = this->GetWnd( index );
- this->DeleteItem( index );
- wnd->SendMessage( WM_CLOSE );
- if( this->GetItemCount( ) <= index )
- index--;
- if( index >= 0 )
- this->SetCurSel( index );
- }
- if( ! this->GetItemCount( ) )
- this->ShowWindow( SW_HIDE );
- }
- void CTabWnd::OnPaint()
- {
- CPaintDC dc( this );
- CDC memDC;
- memDC.CreateCompatibleDC( &dc );
- CBitmap b;
- CRect rc;
- dc.GetClipBox( &rc );
- b.CreateCompatibleBitmap( &dc , rc.Width( ) , rc.Height( ) );
- memDC.SelectObject( &b );
- CTabCtrl::DefWindowProc( WM_PAINT ,( WPARAM )memDC.GetSafeHdc( ) , 0 );
- dc.FillSolidRect( &rc , RGB( 214 , 239 , 255 ) );
- ::TransparentBlt( dc.GetSafeHdc( ) , 0 , 0 , rc.Width( ) , rc.Height( ) , memDC.GetSafeHdc( ) , 0 , 0 , rc.Width( ) , rc.Height( ) , RGB( 0 , 0 , 0 ) );
- }
- void CTabWnd::DrawItem( LPDRAWITEMSTRUCT lpDS )
- {
- CDC dc;
- dc.Attach( lpDS->hDC );
- char buf[255];
- TCITEM item;
- item.mask = TCIF_TEXT;
- item.pszText = buf;
- item.cchTextMax = sizeof( buf );
- this->GetItem( lpDS->itemID , &item );
- dc.SetBkMode( TRANSPARENT );
- dc.SetTextColor( RGB( 10 , 10 , 10 ) );
- CRect rc( lpDS->rcItem );
- if( lpDS->itemID == this->GetCurSel( ) )
- rc.OffsetRect( 1 , 3 );
- dc.DrawText( buf , &rc , DT_CENTER );
- dc.Detach( );
- }