Bitmap button and toolbar - %n.mtb

In this section:

%tb (Bitmap Button) has been superceded by %ib (Image Button) which in turn has been superseded by %mb (Multi-button Toolbar). For new code use %mb instead.

This format defines a bit mapped button or a whole toolbar. The names of three bitmap resources representing the off state, on state, and depressed state should be supplied as character string arguments, followed by an INTEGER argument that represents the state (0 = off, 1 = on). In the absence of a call-back function, pressing the button toggles the state, but does not close the format window. The correct order for the arguments is as follows:

'BMPoff', 'BMPon', 'BMPdown', ControlVariable, Callback

Any button on the toolbar can be set to an inactive/disabled state by using the (~) tilde format modifier. An extra bitmap will be required to represent this state.

For example:

BMPoff', 'BMPon', 'BMPdown', 'BMPdisabled', ControlVariable,
 GreyControlVariable, Callback

The caret character (^) is used in association with a call-back function and this will be called whenever the user clicks on the button.

In order to obtain the effect of a non-toggling button, simply specify the same bitmap for the on and off states, and supply a call-back function to respond to each button press. Note that bitmaps may look different on screens of different resolutions. Where necessary the program should supply the appropriate bitmaps for the resolution in use. Bitmaps can be created using the standard Microsoft "Paint" accessory.

Here is a simple example of the use of bitmap buttons:

  WINAPP 0,0,'d20.rc'
  INCLUDE <windows.ins>
  INTEGER answer

The file d20.rc contains:


Using the optional parameters n and m it is possible to create a whole toolbar as a rectangular array of buttons n items across by m deep. For example, a 1-deep horizontal bar of 10 items would be represented by %10.1tb (or just %10tb) together with 30 bitmap resources as the corresponding arguments.

If call-back functions are used, these follow each set of bitmaps thus: 'off1', 'on1', 'down1', func1, 'off2', 'on2', 'down2', func2,... etc. If the "?" modifier is used, then n × m help strings must be provided. It is particularly valuable to provide such help in the case of toolbar buttons, since their meaning is not always obvious. The following example creates a 3-element horizontal toolbar with help information and call-back functions. The second button is initially set to the on state.

   WINAPP 0,0,'d21.rc'
   INCLUDE <windows.ins>
   INTEGER b1,b2,b3
   EXTERNAL func1,func2,func3
   DATA b1,b2,b3/0,1,0/
  1    'OFF1','ON1','DWN1',b1,func1,
  2    'OFF2','ON2','DWN2',b2,func2,
  3    'OFF3','ON3','DWN3',b3,func3)
   INTEGER function func1()

The file d21.rc contains:


Bitmap buttons can be ganged together (see %ga (Gang Controls)). A greyed bar can also be drawn around the tool bar (see Toolbar border).



Copyright © 1999-2024 Silverfrost Limited