Professional UI Solutions
Site Map   /  Register
 
 
 

Tabbed Toolbars

Is there a way to know when a tab is clicked when using a CExtTabbedToolControlBar?

You can catch both events: when the clicked tab is about to get selected (you can cancel the selection) and when the tab has become selected. Here is the code that allows you to do this.
// Custom class that modifies the tab strip

class CMyTabWnd : public CExtTWPC < CExtTabWnd >
{
protected:
   virtual INT OnTabWndGetParentSizingMargin(
         DWORD dwOrientation
         ) const
   {
         ASSERT_VALID( this );
         if(         dwOrientation == __ETWS_ORIENT_RIGHT
               ||    dwOrientation == __ETWS_ORIENT_BOTTOM
               )
               return 1;
         return 3;
   }
   virtual void OnTabWndEraseClientArea(
         CDC & dc,
         CRect & rcClient,
         CRect & rcTabItemsArea,
         CRect & rcTabNearBorderArea,
         DWORD dwOrientation,
         bool bGroupedMode
         )
   {
         ASSERT_VALID( this );
         ASSERT( dc.GetSafeHdc() != NULL );
         PmBridge_GetPM()->PaintTabbedTabClientArea(
               dc,
               rcClient,
               rcTabItemsArea,
               rcTabNearBorderArea,
               dwOrientation,
               bGroupedMode,
               this
               );
   }
   virtual void OnTabWndDrawItem(
         CDC & dc,
         CRect & rcTabItemsArea,
         LONG nItemIndex,
         TAB_ITEM_INFO * pTii,
         bool bTopLeft,
         bool bHorz,
         bool bSelected,
         bool bCenteredText,
         bool bGroupedMode,
         bool bInGroupActive,
         bool bInvertedVerticalMode,
         const CRect & rcEntireItem,
         CSize sizeTextMeasured,
         CFont * pFont,
         __EXT_MFC_SAFE_LPCTSTR sText,
         CExtCmdIcon * pIcon
         )
   {
         ASSERT_VALID( this );
         ASSERT_VALID( pTii );
         pTii;
         ASSERT( dc.GetSafeHdc() != NULL );
         ASSERT( pFont != NULL );
         ASSERT( pFont->GetSafeHandle() != NULL );
         if( (pTii->GetItemStyle() & __ETWI_CENTERED_TEXT) != 0 )
               bCenteredText = true;
         PmBridge_GetPM()->PaintTabItem(
               dc,
               rcTabItemsArea,
               bTopLeft,
               bHorz,
               bSelected,
               bCenteredText,
               bGroupedMode,
               bInGroupActive,
               bInvertedVerticalMode,
               rcEntireItem,
               sizeTextMeasured,
               pFont,
               sText,
               pIcon,
               this,
               nItemIndex,
               PmBridge_GetPM()->GetColor( COLOR_BTNTEXT )
               );
   }
};

// Custom tabbed page container 
// (replaces standard tab strip with modified one, handles tab selection)

class CMyTabPageContainerWnd : public CExtTabPageContainerWnd
{
public:
   virtual CExtTabWnd * OnTabWndGetTabImpl()
   {
         ASSERT_VALID( this );
         return new CMyTabWnd;
   }
   virtual bool OnTabWndSelectionChange(
         LONG nOldItemIndex,
         LONG nNewItemIndex,
         bool bPreSelectionTest
         )
   {
         bool bRetVal =
               CExtTabPageContainerWnd::OnTabWndSelectionChange(
                     nOldItemIndex,
                     nNewItemIndex,
                     bPreSelectionTest
                     );
         if( bPreSelectionTest )
               ::AfxMessageBox( _T("Tab is about to get selected.") );
         else
               ::AfxMessageBox( _T("Tab has become selected.") );
         return bRetVal;
   }
};


// Custom tabbed toolbar that uses the custom tabbed page container

class CMyTabbedBar : public CExtTabbedToolControlBar
{
protected:
   virtual CExtTabPageContainerWnd * OnTabPageContainerCreateObject()
   {
         ASSERT_VALID( this );
         ASSERT( GetSafeHwnd() != NULL );
         CExtTabPageContainerWnd * pTabPageContainerWnd = NULL;
         try
         {
               pTabPageContainerWnd = new CMyTabPageContainerWnd;
         } // try
         catch( CException * pException )
         {
               ASSERT( FALSE );
               pException->Delete();
               pTabPageContainerWnd = NULL;
         } // catch( CException * pException )
         return pTabPageContainerWnd;
   }
};

If you have any questions, please visit our forum or contact our technical support team at support@prof-uis.com.