FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

MENUS

Add a hierarchical menu from a resource


Here's two functions that should do what you want. As designed, they do not allow you to reset a command key equivalent if one was there before adding the submenu. I've left that as an exercise for the reader. :)

_menuMark = 27

' -------------------------------------------------
' FN AddHierResMenu adds a submenu to a specific menu item using
' a MENU resource.
'
' INPUT:
' addMenuID% Specifies the menu to receive the submenu
' addItemID% Specifies the menu item to receive the submenu
' resMenuID% The MENU resource ID of the menu to insert as
' a submenu
' OUTPUT: Noe
' -------------------------------------------------
'
LOCAL FN AddHierResMenu( addMenuID%, addMenuItem%, resMenuID% )
  DIM thisMenuH&, resMenuH&

  resMenuH& = FN GETMENU( resMenuID% )
  LONG IF resMenuH& <> _nil
    thisMenuH& = FN GETMENU( addMenuID% )
    LONG IF mHndl& <> _nil
      CALL SETITEMCMD( thisMenuH&, addMenuItem%, _menuMark )
      CALL SETITEMMARK( thisMenuH&, addMenuItem%, resMenuID% )
    END IF
    CALL INSERTMENU( resMenuH&, -1 )
  END IF
END FN

' -------------------------------------------------
' FN DeleteHierMenu removes a submenu from a specific menu
' item on the menubar.
'
' INPUT:
' delMenuID% Specifies the menu containing the submenu
' delItemID% Specifies the menu item with the submenu
' to remove.
' OUTPUT: None
' -------------------------------------------------
'
LOCAL FN DeleteHierMenu( delMenuID%, delMenuItem% )
  DIM thisMenuH&

  thisMenuH& = FN GETMENU( delMenuID% )
  LONG IF thisMenuH& <> _nil
    CALL SETITEMCMD( thisMenuH&, delMenuItem%, 0 )
    CALL SETITEMMARK( thisMenuH&, delMenuItem%, _noMark )
  END IF
END FN

L. Frank Turovich