Creating a Tab Control

Other versions of this page are also available for the following:

Windows Mobile Not SupportedWindows Embedded CE Supported

8/28/2008

A tab control is analogous to a set of dividers in a notebook or labels in a file cabinet. In a property sheet, a user selects a tab in order to move from one page in a property sheet to another. The following illustration shows a Windows Embedded CE tab control.

Aa921319.552da964-54d3-490a-955f-36828d1e98ca(en-us,MSDN.10).gif

You send messages to a tab control to add tabs, and to affect the appearance and behavior of the control. Each message has a corresponding macro, which you can use instead of sending the message explicitly. Although you cannot disable an individual tab in a tab control, you can disable a tab control in a property sheet by disabling the corresponding page.

Each tab in a tab control consists of a label and application-defined data. This data is specified by a TCITEM structure. You can add tabs to a tab control, get the number of tabs, retrieve and set the contents of a tab, and delete tabs. Tabs are identified by their zero-based index.

Windows Embedded CE supports an extended style for the tab control. To set an extended style, you can use the TCM_SETEXTENDEDSTYLE message or its corresponding macro, TabCtrl_SetExtendedStyle. You can use the TCM_GETEXTENDEDSTYLE message or its corresponding macro, TabCtrl_GetExtendedStyle, to retrieve the extended style.

Note

Because an extended style for a tab control is not the same as an extended window style, you cannot pass an extended style for a tab control to CreateWindowEx when you create a tab control.

The extended style for the tab control, known as the TCS_EX_FLATSEPARATORS style, draws a separator between tab items in tab controls that have the TCS_BUTTONS style or the TCS_FLATBUTTONS style. When you create a tab control that uses either the TCS_BUTTONS or the TCS_FLATBUTTONS style, the extended style for the tab control is set by default.

To create a tab control

  1. Specify the WC_TABCONTROL class in the lpClassName parameter of the CreateWindowEx function.

    Windows Embedded CE registers this class when it loads the DLL for the common control. You can use the InitCommonControls function to ensure that this DLL is loaded. To register the class for the tab control by using the InitCommonControlsEx function, specify the ICC_ TAB_CLASSES flag as the dwICC member of the INITCOMMONCONTROLSEX structure that you pass in the lpInitCtrls parameter.

  2. Specify a style for the tab control in the dwStyle parameter of the CreateWindowEx function.

You can add tabs to the control by using the TCM_INSERTITEM message, which specifies the position of the tab and the address of its TCITEM structure. You can retrieve and set the contents of an existing tab by using the TCM_GETITEM and TCM_SETITEM messages. For each tab, you can specify an icon, a label, or both.

You can associate application-defined data with each tab. For example, you might save information about each page with its corresponding tab. By default, a tab control allocates four extra bytes per tab for application-defined data. You can change the number of extra bytes per tab by using the TCM_SETITEMEXTRA message. You can use this message only when the tab control is blank.

The lParam member of the TCITEM structure specifies application-defined data. If you use more than four bytes of application-defined data, you need to define your own structure and use it instead of TCITEM. You can retrieve and set application-defined data in the same way that you retrieve and set other information about a tab, by using the TCM_GETITEM and TCM_SETITEM messages.

Note

Windows Embedded CE does not support vertical text. If you create vertical tabs and want to use vertical text, you have to create a text bitmap and rotate it. Then, you can add the bitmap to an image list and attach it to the tab by specifying the index of the bitmap in the image list in the iImage member of the TCITEM structure or the TCITEMHEADER structure.

You use messages and styles to learn about tabs. You can determine the current bounding rectangle for a tab by using the TCM_GETITEMRECT message. You can determine which tab, if any, is at a specified location by using the TCM_HITTEST message. In a tab control that uses the TCS_MULTILINE style, you can determine the current number of rows of tabs by using the TCM_GETROWCOUNT message.

See Also

Concepts

Working with Common Controls