Dynamic Menus

In this section:

If you wish to add or remove menu items whilst the program is running then this is possible with the aid of a handle:

i=winio@('%mn[&Window[*]] &', handle)

The asterisk (*) causes %mn (Menu) to provide a handle that is passed to either ADD_MENU_ITEM@ or REMOVE_MENU_ITEM@. Note that items are added to the end of the pop-down menu that contains the handle. You may have a number of handles for various pop-down menus.

Only one handle is required to create a menu with multiple entries. To detect which menu entry has been selected use CLEARWIN_STRING@('CURRENT_MENU_ITEM') to obtain the text of the menu item selected.

Here is some sample code that illustrates how to add a list of files to a file menu.

      INCLUDE <windows.ins>
      INTEGER i,ctrl,cb,cb0
      INTEGER(7) handle
      CHARACTER*129 fname
      EXTERNAL cb,cb0
      COMMON ctrl
      i=winio@('%mn[[Open]]&',   cb)
      i=winio@('%mn[[Save,|]]&', cb)
      DO i=1,3
        WRITE(fname,'(a,I1)') 'File',i
        CALL add_menu_item@(handle,fname,1,0,cb)
      CALL add_menu_item@(handle,CHAR(0),0,0,cb)
      CALL add_menu_item@(handle,'Exit', 1,0,cb0)
      INCLUDE <windows.ins>
      INTEGER ctrl
      COMMON ctrl
      CALL window_update@(ctrl)



Copyright © 1999-2024 Silverfrost Limited