//by Richard Russell, August 2006//\\ \\ A **rebar control** acts a bit like a toolbar, but instead of being a simple bar it consists of a number of **bands** each of which can contain a **child window**. Typically the child window can itself be a **toolbar** or a **combo box** or indeed any other Windows control. A simple rebar control looks like this (in the Windows XP Visual Style):\\ \\ {{rebar.gif}}\\ \\ This control has two bands, the first containing a combo box and the second a toolbar. Each band contains a **gripper** (the dotted vertical line in this case), a background bitmap (not used here) an optional text string and a child control. The user can dynamically resize and reposition each of the bands by dragging the gripper; if necessary the rebar control can extend over two or more strips.\\ \\ Rebar controls are very flexible, and are often used in Microsoft products instead of simple toolbars.\\ \\ The remainder of this article will describe the steps needed to create a rebar control in //BBC BASIC for Windows//; the code listed will create the control shown above. Firstly we must install the **WINLIB5A** library file which is needed by the program:\\ \\

//by Richard Russell, August 2006//\\ \\ A **rebar control** acts a bit like a toolbar, but instead of being a simple bar it consists of a number of **bands** each of which can contain a **child window**. Typically the child window can itself be a **toolbar** or a **combo box** or indeed any other Windows control. A simple rebar control looks like this (in the Windows XP Visual Style):\\ \\ {{rebar.gif}}\\ \\ This control has two bands, the first containing a combo box and the second a toolbar. Each band contains a **gripper** (the dotted vertical line in this case), a background bitmap (not used here) an optional text string and a child control. The user can dynamically resize and reposition each of the bands by dragging the gripper; if necessary the rebar control can extend over two or more strips.\\ \\ Rebar controls are very flexible, and are often used in Microsoft products instead of simple toolbars.\\ \\ The remainder of this article will describe the steps needed to create a rebar control in //BBC BASIC for Windows//; the code listed will create the control shown above. Firstly we must install the **WINLIB5A** library file which is needed by the program:\\ \\

+

<code bb4w>

INSTALL @lib$+"​WINLIB5A"​

INSTALL @lib$+"​WINLIB5A"​

+

</​code>​

Note that version 1.2 or later of the library is required for this application.\\ \\ Next we must define some data structures used by the program; an INITCOMMONCONTROLSEX structure, a REBARINFO structure and a REBARBANDINFO structure:​\\ \\

Note that version 1.2 or later of the library is required for this application.\\ \\ Next we must define some data structures used by the program; an INITCOMMONCONTROLSEX structure, a REBARINFO structure and a REBARBANDINFO structure:​\\ \\

InitCommonControlsEx is now called to enable the classes required by the rebar control:\\ \\

InitCommonControlsEx is now called to enable the classes required by the rebar control:\\ \\

+

<code bb4w>

ICC_COOL_CLASSES = &400

ICC_COOL_CLASSES = &400

ICC_BAR_CLASSES = 4

ICC_BAR_CLASSES = 4

Line 14:

Line 19:

icex.dwICC% ​ = ICC_COOL_CLASSES OR ICC_BAR_CLASSES

icex.dwICC% ​ = ICC_COOL_CLASSES OR ICC_BAR_CLASSES

SYS "​InitCommonControlsEx",​ icex{}

SYS "​InitCommonControlsEx",​ icex{}

+

</​code>​

Now we are ready to create the rebar control itself:\\ \\

Now we are ready to create the rebar control itself:\\ \\

+

<code bb4w>

RBS_VARHEIGHT = &200

RBS_VARHEIGHT = &200

CCS_NODIVIDER = &40

CCS_NODIVIDER = &40

Line 24:

Line 31:

\ RBS_VARHEIGHT OR CCS_NODIVIDER,​ WS_EX_TOOLWINDOW)

\ RBS_VARHEIGHT OR CCS_NODIVIDER,​ WS_EX_TOOLWINDOW)

IF hRB% = 0 ERROR 100, "​Couldn'​t create ReBar window"​

IF hRB% = 0 ERROR 100, "​Couldn'​t create ReBar window"​

+

</​code>​

The RB_SETBARINFO message is sent to specify an image list, if any (none is used in this example):\\ \\

The RB_SETBARINFO message is sent to specify an image list, if any (none is used in this example):\\ \\

+

<code bb4w>

RB_SETBARINFO = &404

RB_SETBARINFO = &404

rbi.cbSize% = DIM(rbi{})

rbi.cbSize% = DIM(rbi{})

Line 31:

Line 40:

SYS "​SendMessage",​ hRB%, RB_SETBARINFO,​ 0, rbi{} TO res%

SYS "​SendMessage",​ hRB%, RB_SETBARINFO,​ 0, rbi{} TO res%

IF res% = 0 ERROR 100, "​Couldn'​t send ReBar info"

IF res% = 0 ERROR 100, "​Couldn'​t send ReBar info"

+

</​code>​

If you do want to specify an image list set "​rbi.fMask%"​ to "​_RBIM_IMAGELIST"​ (=1) and set "​rbi.himl%"​ to the handle of the image list.\\ \\ Next we initialise the REBARBANDINFO structure members which are common to all the bands:\\ \\

If you do want to specify an image list set "​rbi.fMask%"​ to "​_RBIM_IMAGELIST"​ (=1) and set "​rbi.himl%"​ to the handle of the image list.\\ \\ Next we initialise the REBARBANDINFO structure members which are common to all the bands:\\ \\

+

<code bb4w>

RBBIM_STYLE = 1

RBBIM_STYLE = 1

RBBIM_TEXT = 4

RBBIM_TEXT = 4

Line 44:

Line 55:

\ RBBIM_CHILD OR RBBIM_CHILDSIZE OR RBBIM_SIZE

\ RBBIM_CHILD OR RBBIM_CHILDSIZE OR RBBIM_SIZE

rbBand.fStyle% = RBBS_CHILDEDGE OR RBBS_FIXEDBMP

rbBand.fStyle% = RBBS_CHILDEDGE OR RBBS_FIXEDBMP

+

</​code>​

If you want to specify a background bitmap include "​_RBBIM_BACKGROUND"​ in the "​rbBand.fMask%"​ value and set "​rbBand.hbmBack%"​ to the handle of the required image.\\ \\ At this stage we have a rebar control, but have not yet created any bands. The first band will contain a combo box, so we first create a combo box in the usual way:\\ \\

If you want to specify a background bitmap include "​_RBBIM_BACKGROUND"​ in the "​rbBand.fMask%"​ value and set "​rbBand.hbmBack%"​ to the handle of the required image.\\ \\ At this stage we have a rebar control, but have not yet created any bands. The first band will contain a combo box, so we first create a combo box in the usual way:\\ \\

+

<code bb4w>

CBS_DROPDOWN = 2

CBS_DROPDOWN = 2

hCB% = FN_combobox(hRB%,​ "",​ 0, 0, 0, 100, 200, CBS_DROPDOWN)

hCB% = FN_combobox(hRB%,​ "",​ 0, 0, 0, 100, 200, CBS_DROPDOWN)

IF hCB% = 0 ERROR 100, "​Couldn'​t create combobox"​

IF hCB% = 0 ERROR 100, "​Couldn'​t create combobox"​

+

</​code>​

The height of the combo box (100 in this example) should be set large enough for the drop-down section; it is necessary when XP Visual Styles are //not// in use. The value **200** is the ID number of the combo box.\\ \\ For the purposes of demonstration we will populate the combo box with a couple of items:\\ \\

The height of the combo box (100 in this example) should be set large enough for the drop-down section; it is necessary when XP Visual Styles are //not// in use. The value **200** is the ID number of the combo box.\\ \\ For the purposes of demonstration we will populate the combo box with a couple of items:\\ \\

+

<code bb4w>

CB_ADDSTRING = 323

CB_ADDSTRING = 323

SYS "​SendMessage",​ hCB%, CB_ADDSTRING,​ 0, "Combo box item 0"

SYS "​SendMessage",​ hCB%, CB_ADDSTRING,​ 0, "Combo box item 0"

SYS "​SendMessage",​ hCB%, CB_ADDSTRING,​ 0, "Combo box item 1"

SYS "​SendMessage",​ hCB%, CB_ADDSTRING,​ 0, "Combo box item 1"

+

</​code>​

Now set the REBARBANDINFO structure members that are relevant to the combo box:\\ \\

Now set the REBARBANDINFO structure members that are relevant to the combo box:\\ \\

+

<code bb4w>

DIM rc{l%, t%, r%, b%}

DIM rc{l%, t%, r%, b%}

SYS "​GetWindowRect",​ hCB%, rc{}

SYS "​GetWindowRect",​ hCB%, rc{}

Line 61:

Line 78:

rbBand.cyMinChild% = rc.b% - rc.t%

rbBand.cyMinChild% = rc.b% - rc.t%

rbBand.cx% ​ = 220

rbBand.cx% ​ = 220

+

</​code>​

Note the use of **GetWindowRect** to discover the height of the combo box; the rebar control uses that to determine the height of the band. The value **220** is the initial width of the band in pixels.\\ \\ We are now ready to add the first band, containing the combo box:\\ \\

Note the use of **GetWindowRect** to discover the height of the combo box; the rebar control uses that to determine the height of the band. The value **220** is the initial width of the band in pixels.\\ \\ We are now ready to add the first band, containing the combo box:\\ \\

+

<code bb4w>

RB_INSERTBAND = &401

RB_INSERTBAND = &401

SYS "​SendMessage",​ hRB%, RB_INSERTBAND,​ -1, rbBand{}

SYS "​SendMessage",​ hRB%, RB_INSERTBAND,​ -1, rbBand{}

+

</​code>​

The value **-1** tells Windows to insert the band at the end of the rebar control.\\ \\ The second band, containing the toolbar, can now be created. First create the toolbar itself:\\ \\

The value **-1** tells Windows to insert the band at the end of the rebar control.\\ \\ The second band, containing the toolbar, can now be created. First create the toolbar itself:\\ \\

+

<code bb4w>

TBSTYLE_TRANSPARENT = &8000

TBSTYLE_TRANSPARENT = &8000

CCS_NORESIZE = 4

CCS_NORESIZE = 4

Line 71:

Line 92:

\ TBSTYLE_TRANSPARENT OR CCS_NORESIZE OR CCS_NODIVIDER,​ 0)

\ TBSTYLE_TRANSPARENT OR CCS_NORESIZE OR CCS_NODIVIDER,​ 0)

IF hTB% = 0 ERROR 100, "​Couldn'​t create toolbar"​

IF hTB% = 0 ERROR 100, "​Couldn'​t create toolbar"​

+

</​code>​

For the purposes of demonstration we will add four buttons to the toolbar:\\ \\

For the purposes of demonstration we will add four buttons to the toolbar:\\ \\

Here the pairs of values in the DATA statement are the button'​s image index and the button'​s ID number respectively.\\ \\ Rather than use custom button images we will use the standard set of large button images:\\ \\

Here the pairs of values in the DATA statement are the button'​s image index and the button'​s ID number respectively.\\ \\ Rather than use custom button images we will use the standard set of large button images:\\ \\

+

<code bb4w>

IDB_STD_LARGE_COLOR = 1

IDB_STD_LARGE_COLOR = 1

DIM tbab{hInst%,​ nID%}

DIM tbab{hInst%,​ nID%}

Line 96:

Line 121:

TB_ADDBITMAP = &413

TB_ADDBITMAP = &413

SYS "​SendMessage",​ hTB%, TB_ADDBITMAP,​ nbuttons%, tbab{}

SYS "​SendMessage",​ hTB%, TB_ADDBITMAP,​ nbuttons%, tbab{}

+

</​code>​

Now set the REBARBANDINFO structure members that are relevant to the toolbar:\\ \\

Now set the REBARBANDINFO structure members that are relevant to the toolbar:\\ \\

+

<code bb4w>

TB_GETBUTTONSIZE = &43A

TB_GETBUTTONSIZE = &43A

SYS "​SendMessage",​ hTB%, TB_GETBUTTONSIZE,​ 0, 0 TO btnsize%

SYS "​SendMessage",​ hTB%, TB_GETBUTTONSIZE,​ 0, 0 TO btnsize%

Line 105:

Line 132:

rbBand.cyMinChild% = btnsize% >>>​ 16

rbBand.cyMinChild% = btnsize% >>>​ 16

rbBand.cx% ​ = 250

rbBand.cx% ​ = 250

+

</​code>​

Note that this time we find the size of the buttons; the rebar control uses this and the other height values to determine the height of the strip. The value **250** is the initial width of the band in pixels.\\ \\ Finally we can add the second band, containing the toolbar:\\ \\

Note that this time we find the size of the buttons; the rebar control uses this and the other height values to determine the height of the strip. The value **250** is the initial width of the band in pixels.\\ \\ Finally we can add the second band, containing the toolbar:\\ \\

+

<code bb4w>

SYS "​SendMessage",​ hRB%, RB_INSERTBAND,​ -1, rbBand{}

SYS "​SendMessage",​ hRB%, RB_INSERTBAND,​ -1, rbBand{}

+

</​code>​

Again the **-1** tells Windows to insert the band at the end, but we could instead have specified the value 0 to insert the toolbar band //before// the combo box band.\\ \\ Once the rebar control has been created you can receive notifications from its child controls in the usual way using **ON SYS**.

Again the **-1** tells Windows to insert the band at the end, but we could instead have specified the value 0 to insert the toolbar band //before// the combo box band.\\ \\ Once the rebar control has been created you can receive notifications from its child controls in the usual way using **ON SYS**.