Silverfrost Logo About Us | Contact Us
 

Dynamic Menus

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 to provide a handle that is passed to either add_menu_item@ (see add_menu_item@) or remove_menu_item@ (see 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,handle,ctrl,cb,cb0
      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

 

 

Copyright © 1999-2017 Silverfrost Limited