BBjWindow::addMenuButton

Description

In BBj 7.00 and higher, this method creates menu button control (a button with an optional dropdown menu) in the BBjWindow.

Syntax

Return Value

Method

BBjMenuButton

addMenuButton(int ID, number x, number y, number w, number h, string title)

BBjMenuButton

addMenuButton(int ID, number x, number y, number w, number h, string title, string flags)

BBjMenuButton

addMenuButton(int ID, string title)

BBjMenuButton

addMenuButton(int ID, string title, string flags)

BBjMenuButton

addMenuButton(string title)

BBjMenuButton

addMenuButton(string title, string flags)

Parameters

Variable

Description

ID

Control ID number. It must be an integer between 1 and 32767 and be unique within a given top-level window.

x

Horizontal position of the upper-left corner of the control in current units.

y

Vertical position of the upper-left corner of the control in current units.

width

Width of the control in current units.

height

Height of the control in current units.

title

Title of the control. Including the '&' before a character in the title causes it to be an accelerator.

flags

Control flags, as follows:

Flag Description
$0001$ Sets the control to be initially disabled.
$0010$ Sets the control to be initially invisible.
$0020$ Designates the control to be part of a keyboard navigation group.
$0800$ Draws a recessed client edge around the control.
$1000$ Draws a raised edge around the control.
$2000$ Paint the button in a style similar to Office 2003.
$4000$ Always paint the border around the control.

Return Value

Returns the created BBjMenuButton object.

Remarks

If the ID parameter is not specified, a control ID is assigned dynamically using getAvailableControlID().

If the x, y, width, and height parameters are not specified, they're all initialized to 0. This is typically for use with DWC windows that dynamically arrange their contents (window creation flag $00100000$).

Example

rem 'Create a BBjMenuButton

rem 'Obtain the instance of the BBjAPI object
let myAPI!=BBjAPI()

rem 'Open the SysGui device
SYSGUI=UNT
OPEN (SYSGUI)"X0"
DIM EVENT$:TMPL(SYSGUI)

rem 'Obtain the instance of the BBjSysGui object
let mySysGui!=myAPI!.getSysGui()

rem 'Set addWindow param values
X=100
Y=100
WIDTH=200
HEIGHT=100
TITLE$="BBj Window"

rem 'Set the current context
mySysGui!.setContext(0)

rem 'Create a window with a title in the current context
myWindow! = mySysGui!.addWindow(X,Y,WIDTH,HEIGHT,TITLE$)

rem 'Create BBjMenuButtons
menuButton1! = myWindow!.addMenuButton(101,0,0,100,22,"MenuButton1")
menuButton2! = myWindow!.addMenuButton(102,100,0,100,22,"MenuButton2")

rem 'Create a dropdown menu
myDropdownMenu!=mySysGui!.addPopupMenu()
myDropdownItem1! = myDropdownMenu!.addMenuItem(-201,"Dropdown Item 1")
myDropdownItem2! = myDropdownMenu!.addMenuItem(-202,"Dropdown Item 2")

rem 'Associate dropdown menu with the buttons
menuButton1!.setDropdownMenu(myDropdownMenu!)
menuButton2!.setDropdownMenu(myDropdownMenu!)

rem 'Create a popup menu
myPopupMenu!=mySysGui!.addPopupMenu()
myPopupItem1! = myPopupMenu!.addMenuItem(-301,"Popup Item 1")
myPopupItem2! = myPopupMenu!.addMenuItem(-302,"Popup Item 2")

rem 'Associate popup menu with the buttons
menuButton1!.setPopupMenu(myPopupMenu!)
menuButton2!.setPopupMenu(myPopupMenu!)

rem 'Register the CALLBACK routines
CALLBACK(ON_BUTTON_PUSH,MenuButton1,mySysGui!.getContext(),MenuButton1!.getID())
CALLBACK(ON_BUTTON_PUSH,MenuButton2,mySysGui!.getContext(),MenuButton2!.getID())
CALLBACK(ON_POPUP_ITEM_SELECT,DropdownItem1,myDropdownMenu!.getID(),myDropdownItem1!.getID())
CALLBACK(ON_POPUP_ITEM_SELECT,DropdownItem2,myDropdownMenu!.getID(),myDropdownItem2!.getID())
CALLBACK(ON_POPUP_ITEM_SELECT,PopupItem1,myPopupMenu!.getID(),myPopupItem1!.getID())
CALLBACK(ON_POPUP_ITEM_SELECT,PopupItem2,myPopupMenu!.getID(),myPopupItem2!.getID())
CALLBACK(ON_CLOSE,APP_CLOSE,mySysGui!.getContext())

rem 'Process Events
process_events

rem 'Callback routine invoked when the user clicks the button
MenuButton1:
    event! = mySysGui!.getLastEvent()
    event$ = mySysGui!.getLastEventString()
    i = msgbox("MenuButton1 was clicked")
return

rem 'Callback routine invoked when the user clicks the button
MenuButton2:
    event! = mySysGui!.getLastEvent()
    event$ = mySysGui!.getLastEventString()
    i = msgbox("MenuButton2 was clicked")
return

rem 'Callback routine invoked when the user selects the first dropdown item
DropdownItem1:
    event! = mySysGui!.getLastEvent()
    event$ = mySysGui!.getLastEventString()
    i = msgbox("Dropdown Item 1 was selected on "+event!.getControl().getText())
return

rem 'Callback routine invoked when the user selects the second dropdown item
DropdownItem2:
    event! = mySysGui!.getLastEvent()
    event$ = mySysGui!.getLastEventString()
    i = msgbox("Dropdown Item 2 was selected on "+event!.getControl().getText())
return

rem 'Callback routine invoked when the user selects the first popup item
PopupItem1:
    event! = mySysGui!.getLastEvent()
    event$ = mySysGui!.getLastEventString()
    i = msgbox("Popup Item 1 was selected on "+event!.getControl().getText())
return

rem 'Callback routine invoked when the user selects the second popup item
PopupItem2:
    event! = mySysGui!.getLastEvent()
    event$ = mySysGui!.getLastEventString()
    i = msgbox("Popup Item 2 was selected on "+event!.getControl().getText())
return

rem 'Callback routine called when the user closes the application window
APP_CLOSE:
release

See Also

BBjAPI

BBjSysGui

BBjControl

BBjWindow

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.