creating_20a_20rebar_20control
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
creating_20a_20rebar_20control [2018/03/31 13:19] – external edit 127.0.0.1 | creating_20a_20rebar_20control [2024/01/05 00:22] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
//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$+" | INSTALL @lib$+" | ||
+ | </ | ||
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: | ||
+ | <code bb4w> | ||
DIM icex{dwSize%, | DIM icex{dwSize%, | ||
DIM rbi{cbSize%, | DIM rbi{cbSize%, | ||
DIM rbBand{cbSize%, | DIM rbBand{cbSize%, | ||
\ iImage%, hwndChild%, cxMinChild%, | \ iImage%, hwndChild%, cxMinChild%, | ||
+ | </ | ||
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% | icex.dwICC% | ||
SYS " | SYS " | ||
+ | </ | ||
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, | \ RBS_VARHEIGHT OR CCS_NODIVIDER, | ||
IF hRB% = 0 ERROR 100, " | IF hRB% = 0 ERROR 100, " | ||
+ | </ | ||
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 " | SYS " | ||
IF res% = 0 ERROR 100, " | IF res% = 0 ERROR 100, " | ||
+ | </ | ||
If you do want to specify an image list set " | If you do want to specify an image list set " | ||
+ | <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 | ||
+ | </ | ||
If you want to specify a background bitmap include " | If you want to specify a background bitmap include " | ||
+ | <code bb4w> | ||
CBS_DROPDOWN = 2 | CBS_DROPDOWN = 2 | ||
hCB% = FN_combobox(hRB%, | hCB% = FN_combobox(hRB%, | ||
IF hCB% = 0 ERROR 100, " | IF hCB% = 0 ERROR 100, " | ||
+ | </ | ||
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 " | SYS " | ||
SYS " | SYS " | ||
+ | </ | ||
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 " | SYS " | ||
Line 61: | Line 78: | ||
rbBand.cyMinChild% = rc.b% - rc.t% | rbBand.cyMinChild% = rc.b% - rc.t% | ||
rbBand.cx% | rbBand.cx% | ||
+ | </ | ||
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 " | SYS " | ||
+ | </ | ||
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, | \ TBSTYLE_TRANSPARENT OR CCS_NORESIZE OR CCS_NODIVIDER, | ||
IF hTB% = 0 ERROR 100, " | IF hTB% = 0 ERROR 100, " | ||
+ | </ | ||
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:\\ \\ | ||
+ | <code bb4w> | ||
nbuttons% = 4 | nbuttons% = 4 | ||
DIM tbb{(nbuttons%-1) iBitmap%, idCommand%, fsState&, | DIM tbb{(nbuttons%-1) iBitmap%, idCommand%, fsState&, | ||
Line 88: | Line 111: | ||
SYS " | SYS " | ||
SYS " | SYS " | ||
+ | </ | ||
Here the pairs of values in the DATA statement are the button' | Here the pairs of values in the DATA statement are the button' | ||
+ | <code bb4w> | ||
IDB_STD_LARGE_COLOR = 1 | IDB_STD_LARGE_COLOR = 1 | ||
DIM tbab{hInst%, | DIM tbab{hInst%, | ||
Line 96: | Line 121: | ||
TB_ADDBITMAP = &413 | TB_ADDBITMAP = &413 | ||
SYS " | SYS " | ||
+ | </ | ||
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 " | SYS " | ||
Line 105: | Line 132: | ||
rbBand.cyMinChild% = btnsize% >>> | rbBand.cyMinChild% = btnsize% >>> | ||
rbBand.cx% | rbBand.cx% | ||
+ | </ | ||
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 " | 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**. | 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**. |
creating_20a_20rebar_20control.1522502352.txt.gz · Last modified: 2024/01/05 00:18 (external edit)