Liberty BASIC Help Online

Image bmpbutton.GIF
BMPBUTTON #handle.ext, filespec, returnVar, corner, posx, posy
This statement adds a button that displays an image to a window created with the OPEN command.
The BMPBUTTON statement must be listed before the statement to OPEN the window that will contain it.  Here is a brief description for each parameter as listed above:
The #handle must be identical to the handle of the window which will contain the bmpbutton.  The bmpbutton may have an optional, unique extension which allows it to receive commands during program execution.  The extension begins with a dot and may include any alpha-numeric characters.  A bmpbutton contained on a window whose handle is #win will have #win as the first part of its handle.  Examples of bmpbutton handles are as follows:
#win                 (no extension)
The filespec parameter contains the full or relative path and filename of the *.bmp file containing the bitmap image that will appear on the button.  There are no width or height parameters in the bmpbutton statement, so the size of the button cannot be set by the program.  It is determined by the size of the bitmap image that will appear on it. See also Path and Filename.
returnVar is expressed as one word and it is not enclosed in quotes.  It cannot be expressed as a string variable. It must begin with a letter, but it can contain numerals as well.  If returnVar is set to a valid branch label enclosed in square brackets, then a button click will cause program execution to continue at the specified branch label.  The code that follows the branch label will be executed when the button is pressed.  If returnVar is the name of a subroutine, then that subroutine will be activated when the button is clicked, and the button handle will be passed into the subroutine as an argument.
If returnVar is not a valid branch label or subroutine name, then the value of returnVar is available to be read when the program is halted at an input var$ statement.  The value will be placed into the specified variable.  An example appears below.
This parameter must be one of the following:  UL, UR, LL, or LR.  It specifies which corner of the window acts as an anchor for the button.  For example, if LR is used, then the button will be located relative to the lower right corner.  If the window size is changed during execution of the program, the button will always appear at the same position, relative to the corner specified as the anchor.
UL = upper left
UR = upper right
LL = lower left
LR = lower right
posx, posy
These parameters set the location for the button relative to the anchor corner.  posx and posy are expressed in pixels. Anchor values of less than one may also be used for posx and posy.  For example, if the anchor corner is UL, posx is .9, and posy is .9, then the button will be positioned 9/10ths of the distance of the window in both x and y from the upper left corner. This method of positioning buttons places them in positions that are relative to the size of the window, rather than anchoring them to a specified corner.
Images for Bmpbuttons
A collection of button images has been included with Liberty BASIC in the folder named "bmp".  The collection includes blank buttons.  A drawing program such as MS Paint can be used to edit and create button images for Liberty BASIC.
Detecting Button Presses
Button presses are read and acted upon when a SCAN statement is issued. If SCAN is not used, then program execution must be halted at an INPUT or WAIT statement in order for a button press to be read and acted upon.
An example that uses a branch label button handler:
bmpbutton #main.arrow, "bmp\arrwbttn.bmp", [arrowClicked], UL, 10, 10
open "Button Example" for window as #main
    notice "The arrow button was clicked.  Goodbye."
    close #main
An example that uses a subroutine button handler:
bmpbutton #main.arrow, "bmp\arrwbttn.bmp", arrowClicked, UL, 10, 10
open "Button Example" for window as #main
sub arrowClicked bttnHandle$
    notice bttnHandle$;" was clicked.  Goodbye."
    close #main
    end sub
An example that retrieves a value with an input statement:
bmpbutton #main.arrow, "bmp\arrwbttn.bmp", yes, UL, 10, 10
bmpbutton #main.button2, "bmp\bluebttn.bmp",  no, UL, 70, 10
open "Use Input Example" for window as #main
#main "trapclose [quit]"
    input answer$
    if answer$ = "yes" then notice "You clicked Okay."
    if answer$ = "no" then notice "You clicked Cancel."
    goto [loop]
    close #main
print #handle.ext, "bitmap bitmapname"
This command sets the bitmap displayed on the button to be a that has been loaded previously with the LOADBMP command. "bitmapname" is not the filename of the bitmap, but the name given to it by the LOADBMP command.  Here is a short program that demonstrates the bitmap bmpbutton command.
  'demonstrate the bitmap command for bmpbuttons
  'clicking the buttons causes the bitmap images
  'displayed on the buttons to change
  WindowWidth = 248
  WindowHeight = 175
  loadbmp "arrow", "bmp\arrwbttn.bmp"
  loadbmp "blue", "bmp\bluebttn.bmp"
  bmpbutton #main.button1, "bmp\blank4.bmp", [button1Click], UL, 22, 11
  bmpbutton #main.button2, "bmp\blank4.bmp", [button2Click], UL, 22, 46
  open "BmpButton Image Changer" for window as #main
  print #main, "trapclose [quit]"
  'wait here for user events
[button1Click]   'Display arrow image on button 2
  print #main.button2, "setfocus"
  print #main.button2, "bitmap arrow"
  print #main.button1, "bitmap blue"
[button2Click]   'Display arrow image on button 1
  print #main.button1, "setfocus"
  print #main.button1, "bitmap arrow"
  print #main.button2, "bitmap blue"
  close #main
print #handle.ext, "locate x y width height"
This command repositions the control in its window.  This is effective when the control is placed inside a window of type window.  The control will not update its size and location until a REFRESH command is sent to the window.  See RESIZER.BAS for an example program.
print #handle.ext, "setfocus"
This causes the control to receive the input focus. This means that any keypresses will be directed to the control.
print #handle.ext, "enable"
This causes the control to be enabled.
print #handle.ext, "disable"
This causes the control to be inactive and grayed-out.
print #handle.ext, "show"
This causes the control to be visible.
print #handle.ext, "hide"
This causes the control to be hidden or invisible.
See also: BUTTON, MENU, Controls and Events

Copyright (C) 2003 Shoptalk Systems
Liberty BASIC -