Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

The CExtTabMdiWnd class, which implements a tab control window, is designed to manage child frames of an MDI application. By default, the tab text is the same as the title of the corresponding document. If there is no document found for a particular MDI child frame, it is the title of the child frame window that is used. This algorithm is implemented in the CExtTabMdiWnd::OnTabWndQueryItemText() virtual method. So, the default text of a tab item can be changed by overriding this method. For instance, if you need to have the tab text the same as the title of the MDI child frame, use a CExtTabMdiWnd-derived class like as follows:

class CMyTabs : public CExtTabMdiWnd
{
protected:
    virtual __EXT_MFC_SAFE_LPCTSTR OnTabWndQueryItemText(
      const TAB_ITEM_INFO * pTii
      ) const
    {
      HWND hWndMdiChildFrame =
        (HWND) ( pTii->LParamGet() );
      ASSERT( hWndMdiChildFrame != NULL );
      ASSERT( ::IsWindow(hWndMdiChildFrame) );
      static CString g_sLastCaptionTextBuffer;
      int nTextLen =  ::GetWindowTextLength( hWndMdiChildFrame );
      if( nTextLen <= 0 )
        return CExtTabMdiWnd::OnTabWndQueryItemText( pTii );
      int nCaptionTextLen =
        ::GetWindowText(
          hWndMdiChildFrame,
          g_sLastCaptionTextBuffer.GetBuffer( nTextLen + 2 ),
          nTextLen + 1
          );
      g_sLastCaptionTextBuffer.ReleaseBuffer();
      if( nCaptionTextLen <= 0 )
        return CExtTabMdiWnd::OnTabWndQueryItemText( pTii );
      return ((LPCTSTR)g_sLastCaptionTextBuffer);
    }
};