Using an Image List with a Rebar Control

Each rebar band can contain, among other things, an image from an associated image list. The following procedure details the necessary steps for displaying an image in a rebar band.

To display images in a rebar band

  1. Attach an image list to your rebar control object by making a call to SetImageList, passing a pointer to an existing image list.

  2. Modify the REBARBANDINFO structure to assign an image to a rebar band:

    • Set the fMask member to RBBIM_IMAGE, using the bitwise OR operator to include additional flags as necessary.

    • Set the iImage member to the image list index of the image to be displayed.

  3. Initialize any remaining data members, such as the size, text, and handle of the contained child window, with the necessary information.

  4. Insert the new band (with the image) with a call to CReBarCtrl::InsertBand, passing the REBARBANDINFO structure.

The following example assumes that an existing image list object with two images was attached to the rebar control object (m_wndReBar). A new rebar band (defined by rbi), containing the first image, is added with a call to InsertBand:

REBARBANDINFO rbi = {0};
rbi.cbSize = sizeof(REBARBANDINFO);
rbi.fMask = RBBIM_BACKGROUND | RBBIM_CHILD | RBBIM_IMAGE | 
   RBBIM_CHILDSIZE | RBBIM_STYLE | RBBIM_TEXT;
rbi.fStyle = RBBS_GRIPPERALWAYS;
rbi.cxMinChild = 200;
rbi.cyMinChild = 50;
rbi.lpText = _T("Band #2");
rbi.cch = 7;
rbi.cx = 300;
rbi.hbmBack = (HBITMAP)m_RebarBitmap;
rbi.iImage = 0;
rbi.hwndChild = (HWND)m_Toolbar2;
m_Rebar.GetReBarCtrl().InsertBand(1, &rbi); 

See Also

Concepts

Using CReBarCtrl

Controls (MFC)