Topic : The GFA-Basic Compendium
Author : GFA Systemtechnik GmbH
Version : GFABasic.HYP v2.98 (12/31/2023)
Subject : Documentation/Programming
Nodes : 899
Index Size : 28056
HCP-Version : 3
Compiled on : Atari
@charset : atarist
@lang :
@default : Document not found
@help : Help
@options : +g -i -s +z
@width : 75
@hostname : STRNGSRV
@hostname : CAB
@hostname : HIGHWIRE
@hostname : THING
View Ref-File' ** Menu management
' MENU_SMP.GFA
'
RESERVE FRE(0)-33000 ! Reserve space for the Resource file
' File is not in 'folder' but RSRC_LOAD() looks further and should find it on current drive
IF RSRC_LOAD("folder\RCS2.RSC")=0
ALERT 1,"Resource not found",1,"End",a%
END
ENDIF
~RSRC_GADDR(0,0,menu_adr%) ! Get menu address
~MENU_BAR(menu_adr%,1) ! Display menu bar
'
' Reserve a Message Buffer of 16 bytes and give variable names to positions within it:
DIM message_buffer&(7) ! Eight words (including 0)
mesg_adr%=V:message_buffer&(0)
ABSOLUTE mesg_type&,mesg_adr%
ABSOLUTE m_title&,mesg_adr%+6
ABSOLUTE m_item&,mesg_adr%+8
'
REPEAT
ev%=EVNT_MULTI(&X110000,0,0,0,0,0,0,0,0,0,0,0,0,0,mesg_adr%,500)
IF BTST(ev%,4) ! a new message has arrived
IF mesg_type&=10 ! reporting a menu event
title$=CHAR{OB_SPEC(menu_adr%,m_title&)} ! find out what it was
item$=CHAR{OB_SPEC(menu_adr%,m_item&)}
PRINT AT(3,20);"Menu title : ";title$;SPC(10)
PRINT AT(3,21);"Menu item : ";item$;SPC(10)
~MENU_TNORMAL(menu_adr%,m_title&,1) ! Un-invert menu title display
ENDIF
ENDIF
UNTIL MOUSEK=2
'
~MENU_BAR(menu_adr%,0) ! Remove menu bar
~RSRC_FREE() ! Release Resource memory
RESERVE ! Return reserved memory to GFA BASIC
END
--> At the beginning of the program a 33k byte area of memory is reserved. It
is returned to the interpreter at the end of the program.
The Resource file is then loaded into the freed memory area, the address of
the menu tree is determined and the menu is displayed.
EVNT_MULTI() supervises the menu tree, and, in the event that a menu item
is selected, appropriate messages are written into the Message buffer. This
is a 16-byte long area of memory, divided into eight 2-byte words,
conveniently allocated by means of a word-sized array. Using the ABSOLUTE
command, some variables are defined as being located in this array,
enabling elements of it to be referred to by name.
In a REPEAT-UNTIL loop (exited by pressing the right mouse button),
EVNT_MULTI() is called. The first word of the Message buffer (defined as
mesg_type&) then contains the value 10 if a menu item was selected. The
fourth word (m_title&, the 6th and 7th bytes) contains the object number of
the menu title, from beneath which the item was chosen. The object number
of the item is in the fifth word (m_item&, bytes 8 and 9). The other
elements of the buffer are not required here.
Knowing the object numbers of the menu title and the menu item, and that
OB_SPEC(...), in the case of Dialog Box Buttons and Menu items, returns the
address of text terminated with a zero byte, CHAR{} can be used to extract
the texts and put them into strings.
After displaying the menu title and item on the screen, the inverted menu
title is returned to its normal state with MENU_TNORMAL().