Tabs and Tab Attributes

Each tab in a tab control consists of an icon, a label, and application-defined data. This information is specified by a TC_ITEM 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.

To add tabs to a tab control, use the TCM_INSERTITEM message, specifying the position of the item and the address of a TC_ITEM 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 also specify application-defined data to associate with the tab.

You can retrieve the current number of tabs by using the TCM_GETITEMCOUNT message, delete a tab by using the TCM_DELETEITEM message, and delete all tabs in a tab control by using the TCM_DELETEALLITEMS message.

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 only use this message when the tab control is empty.

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

The first member of your structure must be a TC_ITEMHEADER structure, and the remaining members must specify application-defined data. TC_ITEMHEADER is identical to TC_ITEM, except it does not have the lParam member. The difference between the size of your structure and the size of TC_ITEMHEADER should equal the number of extra bytes per tab.