CTab

Win32++

CTab Class

Description

A tab control is window that displays one or more tabs, and a window page.  It is somewhat analogous to the dividers in a notebook or the labels in a file cabinet. By using a tab control, an application can define multiple pages for the same area of a window or dialog box.

CTab is the class which creates a tab control.  The tabs typically have an icon, and some text. The tabs can be displayed either at the top or bottom of the window. Additional buttons to allow the tabs to be listed or closed can also be displayed.

The AddTabPage function is used to add new tabs to the control.  This function provides an opportunity to specify the tab's icon and text, as well as the window which will be used as this tab's page. 

Refer to the documentation that ships with the Microsoft Windows Software Development Kit for more information on the use of tab controls.

CTab Members

Operations

CTab
CTab();
Constructor for CTab
AddTabPage
virtual int AddTabPage(ViewPtr pView, LPCTSTR szTabText, HICON hIcon, UINT idTab);
virtual int AddTabPage(ViewPtr pView, LPCTSTR szTabText, UINT nID_Icon, UINT idTab = 0);
virtual int AddTabPage(ViewPtr pView, LPCTSTR szTabText);
Adds a tab page from the specified view window, tab text and tab icon. AdjustRect
void AdjustRect(BOOL fLarger, RECT *prc) const;
Calculates a tab control's display area given a window rectangle, or calculates the window rectangle that would correspond to a specified display area. DeleteAllItems
BOOL DeleteAllItems() const;
Removes all items from a tab control. DeleteItem
BOOL DeleteItem(int iItem) const;
Removes an item from a tab control. DeselectAll
void DeselectAll(UINT fExcludeFocus) const;
Resets items in a tab control, clearing any that were set to the TCIS_BUTTONPRESSED state. GetActiveView
CWnd* GetActiveView() const;
Returns a pointer to the currently active view window GetAllTabs
std::vector <TabPageInfo>* GetAllTabs() const;
Returns a pointer to the vector of tab page information for all tabs. GetCloseRect
virtual CRect GetCloseRect() const;
Returns the dimensions of the bounding rectangle of the close button. GetCurFocus
int GetCurFocus() const;
Returns the index of the item that has the focus in a tab control. GetCurSel
int GetCurSel() const;
Determines the currently selected tab in a tab control. GetExtendedStyle
DWORD GetExtendedStyle() const;
Retrieves the extended styles that are currently in use for the tab control. GetImageList
CImageList* GetImageList()const;
Returns a pointer to the tab control's image list. GetItem
BOOL GetItem(int iItem, LPTCITEM pitem) const;
Retrieves information about a tab in a tab control. GetItemCount
int GetItemCount() const;
Retrieves the number of tabs in the tab control. GetItemRect
BOOL GetItemRect(int iItem, LPRECT prc) const;
Retrieves the bounding rectangle for the specified tab in a tab control. GetListMenu
virtual CMenu* GetListMenu();
Returns a pointer to the list menu. GetODImageList
CImageList* GetODImageList() const
Returns the image list for owner drawn tabs. GetListRect
virtual CRect GetListRect() const;
Returns the dimensions of the bounding rectangle of the list button. GetRowCount
int GetRowCount() const;
Retrieves the current number of rows of tabs in a tab control. GetShowButtons
BOOL GetShowButtons() const;
Returns TRUE if the list and close buttons are displayed. GetTabFont
CFont* GetTabFont() const;
Returns the CFont used to set the tab's font. GetTabHeight
int GetTabHeight() const;
Returns the height of the tabs. GetTabImageID
virtual int GetTabImageID(UINT nTab) const;
Returns the image ID for the specified tab. GetTabIndex
virtual int GetTabIndex(CWnd* pWnd) const;
Returns the index of the tab given its view window. GetTabPageInfo
virtual TabPageInfo GetTabPageInfo(UINT nTab) const;
Returns the tab page info struct for the specified tab. GetTabText
virtual CString GetTabText(UINT nTab) const;
Returns the text for the specified tab. GetTabsAtTop
virtual BOOL GetTabsAtTop() const;
Returns TRUE if the tabs are displayed at the top of the control, and FALSE if they are displayed at the bottom. GetToolTips
CToolTip* GetToolTips() const;
Retrieves a pointer to the ToolTip control associated with a tab control. HighlightItem
BOOL HighlightItem(INT idItem, WORD fHighlight) const;
Sets the highlight state of a tab item. HitTest
int HitTest(TCHITTESTINFO& info) const;
Determines which tab, if any, is at a specified screen position. InsertItem
int InsertItem(int iItem, const LPTCITEM pItem) const;
Inserts a new tab in a tab control. RecalcLayout
virtual void RecalcLayout();
Repositions the child windows of the tab control. RemoveImage
void RemoveImage(int iImage) const;
Removes an image from a tab control's image list. RemoveTabPage
virtual void RemoveTabPage(int nPage);
Removes a tab page from the control. SelectPage
virtual void SelectPage(int nPage);
Makes the specified tab index the selected tab page. SetCurFocus
void SetCurFocus(int iItem) const;
Sets the focus to a specified tab in a tab control. SetCurSel
int SetCurSel(int iItem) const;
Selects a tab in a tab control. SetExtendedStyle
DWORD SetExtendedStyle(DWORD dwExStyle) const;
Sets the extended styles that the tab control will use. SetFixedWidth
virtual void SetFixedWidth(BOOL bEnabled);
Enable or disable fixed tab width. SetFont
virtual void SetFont(CFont* pFont, BOOL bRedraw = 1);
Sets the font and adjusts the tab height to match. SetImageList
CImageList* SetImageList(CImageList* pImageList) const;
Assigns an image list to a tab control. SetItem
BOOL SetItem(int iItem, LPTCITEM pitem) const;
Sets some or all of a tab's attributes. SetItemExtra
BOOL SetItemExtra(int cb) const;
Sets the number of bytes per tab reserved for application-defined data in a tab control. SetItemSize
DWORD SetItemSize(int cx, int cy) const;
Sets the width and height of tabs. SetMinTabWidth
int SetMinTabWidth(int cx) const;
Sets the minimum width of items in a tab control. SetOwnerDraw
virtual void SetOwnerDraw(BOOL bEnabled);
Enable or disable owner draw. Set owner draw to TRUE to display the tab icons. SetPadding
void SetPadding(int cx, int cy) const;
Sets the amount of space (padding) around each tab's icon and label in a tab control. SetShowButtons
virtual void SetShowButtons(BOOL bShow);
Allows the list and close buttons to be shown or hidden. SetTabHeight
void SetTabHeight(int nTabHeight);
Sets the height of the tabs. SetTabIcon
virtual void SetTabIcon(int i, HICON hIcon);
Change the tab's existing icon, or assigns a new icon if one didn't previously exist. SetTabsAtTop
virtual void SetTabsAtTop(BOOL bTop);
Positions the tabs at the top or bottom of the control. SetTabText
virtual void SetTabText(UINT nTab, LPCTSTR szText);
Sets the text of the specified tab SwapTabs
virtual void SwapTabs(UINT nTab1, UINT nTab2);
Swaps the two specified tabs. SetToopTips
void SetToolTips(CToolTip* pToolTip) const;
Assigns a ToolTip control to a tab control.

Overridables

DrawCloseButton
virtual void DrawCloseButton(CDC& DrawDC);
Draws the close button.
DrawListButton
virtual void DrawListButton(CDC& DrawDC);
Draws the list button.
DrawTabs
virtual void DrawTabs(CDC& dcMem);
Draws the tabs.
DrawTabBorders
virtual void DrawTabBorders(CDC& dcMem, CRect& rcTab);
Draws the tab borders.
OnCreate
virtual void OnCreate();
Called when the tab control is created.
OnEraseBkgnd
virtual LRESULT OnEraseBkgnd(WPARAM wParam, LPARAM lParam);
Called when the tab control's background is redrawn.
OnKillFocus
virtual LRESULT OnKillFocus(WPARAM wParam, LPARAM lParam);
Called when the tab control loses focus.
OnLButtonDblClk
virtual LRESULT OnLButtonDblClk(WPARAM wParam, LPARAM lParam);
Called when the left mouse button is double clicked.
OnLButtonDown
virtual LRESULT OnLButtonDown(WPARAM wParam, LPARAM lParam);
Called when the left mouse button is clicked.
OnLButtonUp
virtual void OnLButtonUp(WPARAM wParam, LPARAM lParam);
Called when the left mouse button is released.
OnMouseLeave
virtual void OnMouseLeave(WPARAM wParam, LPARAM lParam);
Called when the mouse leaves the tab control.
OnMouseMove
virtual void OnMouseMove(WPARAM wParam, LPARAM lParam);
Called when the mouse moves over the tab control.
OnNCHitTest
virtual LRESULT OnNCHitTest(WPARAM wParam, LPARAM lParam);
Called when the mouse moves, or when a mouse button is pressed or released over the tab control (non-client hit test).
OnNotifyReflect
virtual LRESULT OnNotifyReflect(WPARAM wParam, LPARAM lParam);
Called when the tab control sends a notification.
OnSetFocus
virtual LRESULT OnSetFocus(WPARAM wParam, LPARAM lParam);
Called when the tab control gets keyboard focus. We set the keyboard focus to the active view window.
OnTCNSelChange
virtual LRESULT OnTCNSelChange(LPNMHDR pNMHDR);
Called when the currently selected tab has changed
OnWindowPosChanged
virtual LRESULT OnWindowPosChanged(WPARAM wParam, LPARAM lParam);
Called when the window's position has changed.
OnWindowPosChanging
virtual LRESULT OnWindowPosChanging(WPARAM wParam, LPARAM lParam);
Called when the window's position is changing.
Paint
virtual void Paint();
Paints the tab control.
PreCreate
virtual void PreCreate(CREATESTRUCT& cs);
Specifies the window creation parameters before the window is created.
PreRegisterClass
virtual void PreRegisterClass(WNDCLASS &wc);
Set the window class parameters before the window is created
SetTabSize
virtual void SetTabSize();
Sets the size of the tabs.
ShowListDialog
virtual void ShowListDialog();
Displays the list of windows in a dialog.
ShowListMenu
virtual void ShowListMenu();
Displays the list of windows in a popup menu.
Base class Members

For base class members, refer to the members of CWnd.

Remarks

Like all common controls, the tab control requires a parent window. This parent window is often a dialog, but other windows, such as simple windows or Frames, can also be the parent window for a tab control.

The following example shows how to add pages to a tab control.

void CMainFrame::OnInitialUpdate()
{ 	
  // Add some tabs to the tab control
  SetOwnerDraw(TRUE);
  SetFixedWidth(TRUE);
  m_View.AddTabPage(new CViewClasses, _T("Classes"), IDI_CLASSVIEW);
  m_View.AddTabPage(new CViewFiles, _T("Files"), IDI_FILEVIEW);
  m_View.AddTabPage(new CViewClasses, _T("Classes"), IDI_CLASSVIEW);
  m_View.AddTabPage(new CViewFiles, _T("Files"), IDI_FILEVIEW);
  m_View.SelectPage(0);
}

SetOwnerDraw disables or enables owner drawing for the tab control. When owner drawing is enabled, flickering in the tab's view window is reduced and tabs at the bottom of the tab control are drawn properly. When owner drawing is disabled, the tab control reverts back to its default drawing and tab rendering.

Refer to the TabDemo for a demonstration of using CTab as the view window within a Frame, and TabDialogDemo for a demonstration of using CTab in a dialog.

Other Win32++ class that use Tab controls include CTabbedMDI and CDockContainer. CTabbedMDI combines many of the features of a Tab Control and a MDI Frame. CDockContainer is a specialized Tab control intend for use with Dockers.

Summary Information

Header file tab.h
Win32/64 support Yes
WinCE support Yes
Library required Comctl32.lib