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.

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

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited