Contents Previous Next Subchapters

Using A Popup Menu In A Dialog Window
See Also radiobuttons

Dialog "popupmenu" controls are used to display a list from which the user can make one choice.

captiongeometry, "popupmenu", menuindex)
captiongeometry, "popupmenu", menuindexcall back)
Adds a "popupmenu" control, with the specified geometry , to the window specified by caption . The geometry specifies the size of the menu when it is popped up. The character matrix menu specifies the choices in the popup menu. The integer scalar index specifies which row of menu is used for the initial setting of the popup menu (it must be between 1 and the row dimension of menu). The command specified by call back is executed whenever the contents of the popup menu is changed by the user. The return value is the control handle for the popup menu.

Returns the current section in the "popupmenu" control specified by handle, where handle is the value returned by addcontrol when the "popupmenu" control was created. The return value is a character row vector.

Changes the list of choices in the "popupmenu" control specified by handle to the list specified menu, where handle is value returned by addcontrol when the "popupmenu" control was created and menu is a character matrix. The return value of setcontrol is true, if the control can be set as requested, and false otherwise.

The following program creates a dialog window with a push button labeled "Done" and a popup menu. The first time the button is pressed, the list of choices in the popup menu is changed. The second time the button is pressed, the current menu choice is printed in the command window and the dialog is deleted.

Caption  = "Test Dialog"
geometry = [100, 100, 200, 100]
callback = "delwin(Caption);"
adddialog(Caption, geometry, callback);
geometry = [20, 20, 70, 100]
menu     = {"One", "Two", "Three"}
index    = 2
Handle   = addcontrol(Caption, geometry, "popupmenu", menu, index)
geometry = [70, 50, 50, 20]
name     = "Done"
callback = "Done"
addcontrol(Caption, geometry, "pushbutton", name, callback);
count    = 0
function Done() begin
     global count, Handle, Caption
     count = count + 1
     if count == 1 then begin
          menu = {"A 1", "B 2", "C 3", "D 4"}
          setcontrol(Handle, menu);
     print getcontrol(Handle)