Silverfrost Logo About Us | Contact Us
 

Button format - %nbt[button_text]

Note: The syntax for %bb - Button is very similar to %bt and %bb is usually preferred.

This format defines a button where button_text represents a standard character string consisting of the text that is dsiplayed on the button. The text must either be enclosed in square brackets, or an @ symbol is used to indicate that the text is supplied as an argument. The buttons of a dialog box are numbered from 1. The winio@ function returns the number of a button used to close a window or zero if it was closed in some other way (this assumes the button does not have a call-back). Button names may include the "&" character in order to provide accelerator keys.

For example:

i=winio@('Idiot!%ta%bt[&Sorry]')

A grave accent (`) is used to indicate that the button is the default when the Enter key is pressed. A default button has a slightly different appearance.

The caret character (^) may be used to define a call-back function that is called when the user clicks on the button (or, if the button is the default button, when the user presses the Enter key).

For example:

    INTEGER i,winio@
    EXTERNAL func
    i=winio@('Press this to see what happens &')
    i=winio@('%^bt[PRESS]',func)
    END
c---Function to do something---
    INTEGER function func()
     func=1
    END

The buttons in a format window (both %bt and %tt) are numbered from 1 in the order in which they are defined in the format string. When the user clicks on a button that does not have a call-back function, the format window closes and the corresponding winio@ call returns the number of the button pressed. For example:

PRINT *,winio@('%bt[OK]%ta%bt[Cancel]')

outputs the value 1 if 'OK' is pressed, 2 if 'Cancel' is pressed and zero if the window is closed without clicking on a button.

Alternatively, if a button has a call-back function that returns a negative value, then clicking on the button causes the format window to close and the corresponding winio@ call returns this value made positive. For example:

INTEGER winio@,i,func
EXTERNAL func
i=winio@('%^bt[OK]%ta%bt[Cancel]',func)
PRINT *,i
END
INTEGER FUNCTION func()
func=(-1)
END

displays the value +1 if 'OK' is pressed, 2 if 'Cancel' is pressed and zero if the window is closed without clicking on a button.

Normally a button created with %bt is permanently enabled. However, if the tilde (~) format modifier is used then an extra INTEGER argument must be supplied (before any call-back function). This argument provides an integer that controls the state of the button. When this integer is zero the button is greyed and cannot be used. When this integer is 1 the button is enabled. Typically this control integer would be altered by code responding to another control. For example, after a successful file-opening, a number of options might be enabled. Note that there is no reason why the same control integer should not control several buttons and/or menu items.

For example:

    WINAPP
    INCLUDE <windows.ins>
    INTEGER grey_cntrl
    EXTERNAL open_f,save_f,save_as_f
    COMMON grey_cntrl
c---Only the OPEN button is initially available
    grey_cntrl=0
    i=winio@( '%^bt[Open]  &',open_f)
    i=winio@('%~^bt[Save]  &',grey_cntrl,save_f)
    i=winio@('%~^bt[Save as]',grey_cntrl,save_as_f)
    END
c---
    INTEGER function open_f()
     INTEGER grey_cntrl
     COMMON grey_cntrl
     grey_cntrl=1
     open_f=2
    END
    .....

The width of the button, in average characters, can be supplied using the parameter n (e.g. %10bt[Save]) rather than this being determined by the width of its text. A button is created wide enough for at least n characters (possibly more, if the font is not mono-spaced). This enables a number of buttons of the same size to be created. %fn and %ts can be used before %bt in order to modify the button text. %bi is used to add an icon the a button whilst %bc is used to change its background colour.

The text on a button can be changed dynamically by calling change_button_text@.

The text on a button will be placed on more than one line if a line feed character (CHAR(10)) is spliced into the text at the appropriate point.

For example:

button_name='Press'//CHAR(10)//'here'
i=winio@('%bt@',button_name)

 

 

Copyright © 1999-2017 Silverfrost Limited