Items

A header control typically has several header items that define the columns of the control. You add an item to a header control by sending the HDM_INSERTITEM message to the control. The message includes the address of an HD_ITEM structure. This structure defines the properties of the header item, which can include a string, a bitmapped image, an initial size, and an application-defined 32-bit value.

The fmt member of an item's HD_ITEM structure can include either the HDF_STRING or HDF_BITMAP flag, to indicate whether the control displays the item's string or bitmap. If you want to display both a string and a bitmap, create an owner-drawn item by setting the fmt member to include the HDF_OWNERDRAW flag. The HD_ITEM structure also specifies formatting flags that tell the control whether to center, left-align, or right-align the string or bitmap in the item's rectangle.

HDM_INSERTITEM returns the index of the newly added item. You can use the index in other messages to set properties or retrieve information about the item. You can delete an item by using the HDM_DELETEITEM message, specifying the index of the item to delete.

You can use the HDM_SETITEM message to set the properties of an existing header item and the HDM_GETITEM message to retrieve the current properties of an item. To retrieve a count of the items in a header control, use the HDM_GETITEMCOUNT message.

You can use the HBT_SPRING value to give a header item a "springy" quality. Although an item has a minimum width, it can grow wider if there is extra room in the owner window. A header control can have multiple springy items; the extra room in the owner window is distributed among the springy items.

To make an item springy, send the WM_SETTEXT message to the header control. In the wParam parameter, use the logical OR operator to combine the index of the header item with the HBT_SPRING value.