Share via


Using Image Lists with Header Controls

OverviewSample

Header items have the ability to display an image within a header item. This image, stored in an associated image list, is 16 x 16 pixels and has the same characteristics as the icon images used in a list view control. In order to implement this behavior successfully, you must first create and initialize the image list, associate the list with the header control, and then modify the attributes of the header item that will display the image.

The following procedure illustrates the details, using a pointer to a header control (m_pHdrCtrl) and a pointer to an image list (m_pHdrImages).

To display an image in a header item

  1. Construct a new image list (or use an existing image list object) using the constructor, storing the resultant pointer.

  2. Initialize the new image list object by calling . The following code is one example of this call.

    m_pHdrImages->Create(16, 16, ILC_MASK, 2, 2);
    
  3. Add the images for each header item. The following code adds two predefined images.

    m_pHdrImages->Add(pApp->LoadIcon(IDI_ICONHDR1));
    m_pHdrImages->Add(pApp->LoadIcon(IDI_ICONHDR2));
    
  4. Associate the image list with the header control with a call to .

  5. Modify the header item to display an image from the associated image list. The following example assigns the first image, from m_phdrImages, to the first header item, m_pHdrCtrl.

    HDITEM    curItem;
    
    m_pHdrCtrl->SetImageList(m_pHdrImages);
    m_pHdrCtrl->GetItem(0, &curItem);
    curItem.mask= HDI_IMAGE | HDI_FORMAT;
    curItem.iImage= 0;
    curItem.fmt= HDF_LEFT | HDF_IMAGE | HDF_STRING;
    m_pHdrCtrl->SetItem(0, &curItem);
    

For detailed information on the parameter values used, consult the pertinent .

Note   It is possible to have multiple controls using the same image list. For instance, in a standard list view control, there could be an image list (of 16 x 16 pixel images) used by both the small icon view of a list view control and the header items of the list view control.