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
  i=winio@('Hello%ta%tb','BT_OFF','BT_ON','BT_DOWN',answer)
  END

The file d20.rc contains:

BT_OFF  BITMAP "BT1.BMP"
BT_ON   BITMAP "BT2.BMP"
BT_DOWN BITMAP "BT3.BMP"

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/
   i=winio@('%3.1?^tb[Apples][Oranges][Pears]',
  1    'OFF1','ON1','DWN1',b1,func1,
  2    'OFF2','ON2','DWN2',b2,func2,
  3    'OFF3','ON3','DWN3',b3,func3)
   END
c----
   INTEGER function func1()
    func1=1
   END
   ....

The file d21.rc contains:

OFF1 BITMAP "BT1.BMP"
ON1  BITMAP "BT2.BMP"
DWN1 BITMAP "BT3.BMP"
OFF2 BITMAP "BT1.BMP"
ON2  BITMAP "BT2.BMP"
DWN2 BITMAP "BT3.BMP"
OFF3 BITMAP "BT1.BMP"
ON3  BITMAP "BT2.BMP"
DWN3 BITMAP "BT3.BMP"

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

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited