STx 3.9 Documentation

Class

CMenu : CObj

CMenu Examples

//{{3.8 3205}{2006.10.18 13.22.25} - automatically created version information - do not change or delete this line} /*++ Macro: cmenu_example Descriptions: An example of the use of the CMenu class to create and display a context menu in a dialog and react to user input (command selection and hotkeys). Parameters: None Author: Jonnie White History: 2006-10-18 First implemented --*/ [macro cmenu_example] // create a dialog #dmap := cdlgmap * dialog * 'CMenu Test Dialog' if '$#dmap[?]' != 'instance' em -1 ; $#mac::Error - Failed to create CDlgMap instance // create controls $($#dmap setci ok) button 0 0 '&OK' * 8 $($#dmap setci cancel) button 1 0 '&Cancel' * 8 // create cmenu #cmenu := cmenu if '$#cmenu[?]' != 'instance' em -1 ; $#mac::Error - Failed to create CMenu instance // add menu items $#cmenu additem ; menu=item1 ; hotkey=C1 ; cmd=cmd1 ; args=args1 ; id=command1 $#cmenu additem ; menu=item2 ; hotkey=C2 ; cmd=cmd2 ; args=args2 ; id=command2 // add menu to dialog $($#dmap dlg) AddPopup /X 0 $($#cmenu GetTable) /Table if '$rc' > 0 em $rc ; $#mac::Error - Failed to add popup context menu to dialog // display dialog and react to user input $#dmap begin do forever $($#dmap dlg) /Write readstr '$($#dmap loop ok cancel)' #msgId #par $($#dmap dlg) /Read if '$#msgId' == 'command' then // close dialog if '$#par' == 'ok' || '$#par' == 'cancel' break else if '$#msgId' == 'cmstat' then // show context menu $($#dmap Dlg) contextmenu 0 else if '$#msgId' == 'cmitem' then // user selected item, so execute command gosub $($#cmenu GetItem $#par ; cmd) $($#cmenu GetItem $#par ; args) else if '$#msgId' == 'key' then // user pressed hotkey, so execute command readstr '$#par' #code #key gosub $($#cmenu GetItem hotkey=$#key ; cmd) $($#cmenu GetItem hotkey=$#key ; args) end end // destroy dialog and map $#dmap end $#cmenu destroy delete $#t exit cmd1: um command 1 called with these arguments: $#argv exit cmd2: um command 2 called with these arguments: $#argv exit

© 2009 The Austrian Academy of Sciences Acoustics Research Institute