Rebar ControlsRebar Controls*
*Contents  *Index  *Topic Contents
*Previous Topic: PSHNOTIFY
*Next Topic: Rebar Control Reference

Rebar Controls


Rebar controls act as containers for child windows. An application assigns child windows, which are often other controls, to a rebar control band. Rebar controls contain one or more bands, and each band can have any combination of a gripper bar, a bitmap, a text label, and a child window. However, bands cannot contain more than one child window.

arrowy.gifAbout Rebar Controls

arrowy.gifUsing Rebar Controls

arrowy.gifRebar Control Reference

About Rebar Controls

A rebar control displays the child window over a specified background bitmap. As you dynamically reposition a rebar control band, the rebar control manages the size and position of the child window assigned to that band.

The following illustration shows a rebar control that has two bands. One contains a combo box, and the other contains a transparent toolbar control.

Rebar control with bands containing a combo box and a transparent toolbar control.

Note The rebar control is implemented in version 4.70 and later of Comctl32.dll.

Rebar Bands and Child Windows

An application defines a rebar band's traits by using the RB_INSERTBAND and RB_SETBANDINFO messages. These messages accept the address of a REBARBANDINFO structure as the lParam parameter. The REBARBANDINFO structure members define the traits of a given band. To set a band's traits, set the cbSize member to indicate the size of the structure, in bytes. Then set the fMask member to indicate which structure members your application is filling.

To assign a child window to a band, include the RBBIM_CHILD flag in the fMask member of the REBARBANDINFO structure, and then set the hwndChild member to the child window's handle. Applications can set the minimum allowable width and height of a child window in the cxMinChild and cyMinChild members.

When a rebar control is destroyed, it destroys any child windows assigned to the bands within it. To prevent the control from destroying child windows assigned to its bands, remove the bands by sending the RB_DELETEBAND message, and then reset the parent to another window with the SetParent function before destroying the rebar control.

The Rebar Control User Interface

All rebar control bands can be resized, except those that use the RBBS_FIXEDSIZE style. To resize or change the order of bands within the control, click and drag a band's gripper bar. The rebar control automatically resizes and repositions child windows assigned to its bands. Additionally, you can toggle the size of a band by clicking on the band text, if there is any.

The Rebar Control's Image List

If an application is using an image list with a rebar control, it must send the RB_SETBARINFO message before adding bands to the control. This message accepts the address of a REBARINFO structure as the lParam parameter. Before sending the message, prepare the REBARINFO structure by setting the cbSize member to the size of the structure, in bytes. Then, if the rebar control is going to display images on the bands, set the fMask member to the RBIM_IMAGELIST flag and assign an image list handle to the himl member. If the rebar will not use band images, set fMask to zero.

Rebar Control Message Forwarding

A rebar control forwards all WM_NOTIFY window messages to its parent window. Additionally, a rebar control forwards any messages sent to it from windows assigned to its bands, like WM_CHARTOITEM, WM_COMMAND, and others.

Custom Draw Support

Rebar controls support custom draw functionality. For more information, see About Custom Draw.

Using Rebar Controls

This section gives sample code that demonstrates how to implement a rebar control.

Creating a Rebar Control

An application creates a rebar control by calling the CreateWindowEx function, specifying REBARCLASSNAME as the window class. The application must first register the window class by calling the InitCommonControlsEx function, while specifying the ICC_COOL_CLASSES bit in the accompanying INITCOMMONCONTROLSEX structure.

The following sample creates a rebar control with two bands—one that contains a combo box and another that contains a toolbar. The sample includes the RBS_VARHEIGHT style to allow the control to use variable band height. After creating the rebar control, CreateRebar creates the child windows with calls to two application-defined functions, CreateComboBox and CreateToolbar. Before adding each band, CreateRebar initializes the cbSize member of the REBARBANDINFO structure, as required by the RB_INSERTBAND message. Then it sets the value of the structure's fMask member to reflect which members contain valid data. CreateRebar sets the cyMinChild member for each band to allow for the height of the control within it. The cxMinChild member is zero to allow the user to completely hide the control within a given band.

HWND WINAPI CreateRebar(HWND hwndOwner)
{
   REBARINFO     rbi;
   REBARBANDINFO rbBand;
   RECT          rc;
   HWND   hwndCB, hwndTB, hwndRB;
   DWORD  dwBtnSize;
   INITCOMMONCONTROLSEX icex;

   icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
   icex.dwICC   = ICC_COOL_CLASSES|ICC_BAR_CLASSES;
   InitCommonControlsEx(&icex);

   hwndRB = CreateWindowEx(WS_EX_TOOLWINDOW,
                           REBARCLASSNAME,
                           NULL,
                           WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS|
                           WS_CLIPCHILDREN|RBS_VARHEIGHT|CCS_NODIVIDER,
                           0,0,0,0,
                           hwndOwner,
                           NULL,
                           g_hinst,
                           NULL);
   if(!hwndRB)
      return NULL;

   // Initialize and send the REBARINFO structure.
   rbi.cbSize = sizeof(REBARINFO);  // Required when using this struct.
   rbi.fMask  = 0;
   rbi.himl   = (HIMAGELIST)NULL;
   if(!SendMessage(hwndRB, RB_SETBARINFO, 0, (LPARAM)&rbi))
      return NULL;

   // Initialize structure members that both bands will share.
   rbBand.cbSize = sizeof(REBARBANDINFO);  // Required
   rbBand.fMask  = RBBIM_COLORS | RBBIM_TEXT | RBBIM_BACKGROUND | 
                   RBBIM_STYLE | RBBIM_CHILD  | RBBIM_CHILDSIZE | 
                   RBBIM_SIZE;
   rbBand.fStyle = RBBS_CHILDEDGE | RBBS_FIXEDBMP;
   rbBand.hbmBack= LoadBitmap(g_hinst, MAKEINTRESOURCE(IDB_BACKGRND));   
   
   // Create the combo box control to be added.
   hwndCB = CreateComboBox(hwndRB);
   
   // Set values unique to the band with the combo box.
   GetWindowRect(hwndCB, &rc);
   rbBand.lpText     = "Combo Box";
   rbBand.hwndChild  = hwndCB;
   rbBand.cxMinChild = 0;
   rbBand.cyMinChild = rc.bottom - rc.top;
   rbBand.cx         = 200;

   // Add the band that has the combo box.
   SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

   // Create the toolbar control to be added.
   hwndTB = CreateToolbar(hwndOwner, dwStyle);

   // Get the height of the toolbar.
   dwBtnSize = SendMessage(hwndTB, TB_GETBUTTONSIZE, 0,0);

   // Set values unique to the band with the toolbar.
   rbBand.lpText     = "Tool Bar";
   rbBand.hwndChild  = hwndTB;
   rbBand.cxMinChild = 0;
   rbBand.cyMinChild = HIWORD(dwBtnSize);
   rbBand.cx         = 250;

   // Add the band that has the toolbar.
   SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);

   return (hwndRB);
}

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.