TMenuItem

Source: source/classes/menuitem.prg

Standalone class

TMenuItem represents a single entry within a TMenu object. Each item has a prompt, an optional action (code block), a checked/unchecked state, an enabled/disabled state, and a WHEN condition for dynamic visibility. Items can also act as separators or open submenus.

Key DATA Members

DATATypeDescription
cPromptCharacterMenu item text, with & for accelerator underline
nIdNumericCommand ID for the menu item
bActionBlockCode block executed on selection
bWhenBlockCode block evaluated to enable/disable item dynamically
lCheckedLogicalWhether the item shows a check mark
lActiveLogicalWhether the item is enabled (clickable)
lSeparatorLogical.T. for a separator bar
oMenuObjectParent TMenu object containing this item

Methods

MethodDescription
New( cPrompt, cMsg, lChecked, lActive, bAction, bWhen, ... )Create a new menu item
ReDefine( cPrompt, ... )Redefine a menu item from a resource
SetCheck( lOn )Toggle the check mark on/off
Enable()Enable the menu item
Disable()Disable (gray out) the menu item
SetPrompt( cText )Change the menu item text at runtime

Example: Menu Item with Action and Check

#include "FiveWin.ch"

function Main()

   local oWnd, oMenu, oItemStatus

   DEFINE WINDOW oWnd TITLE "TMenuItem Demo" ;
      MENU buildMenu( @oItemStatus )

   ACTIVATE WINDOW oWnd CENTERED

return nil

function buildMenu( oItemStatus )

   local oMenu

   MENU oMenu
      MENUITEM "&View"
      MENU oSub
         MENUITEM "&Toolbar" ACTION MsgInfo( "Toggle Toolbar" )
         MENUITEM "&Status Bar" ;
            ACTION MsgInfo( "Toggle Status Bar" ) ;
            CHECKED
         SEPARATOR
         MENUITEM "E&xit" ACTION oWnd:End()
      ENDMENU
   ENDMENU

return oMenu

Notes

See Also