
BBjWindow::addMenuButton
Description
In BBj 7.0 and higher, this method creates menu button control (a button with an optional dropdown menu) in the BBjWindow.
Syntax
Return Value |
Method |
---|---|
addMenuButton(int ID, int x, int y, int width, int height, string title) |
|
addMenuButton(int ID, int x, int y, int width, int height, string title, string flags) |
|
addMenuButton(int ID, string title) | |
addMenuButton(int ID, string title, string flags) | |
addMenuButton(string title) | |
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:
|
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
See the BBj Object Diagram for an illustration of the relationship between BBj Objects.