Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Force 4.0 Reference - menusetfunc() link a function to a prompt http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 menusetfunc()       Link a function to a prompt
------------------------------------------------------------------------------
 Declaration
   menu.hdr

 Syntax
   func logical menusetfunc extern
   param value _MENU  pMenu, ;
         value int    iId, ;
         value ulong  pFunc

 Arguments
   pMenu is the pointer to a previously created menu system. If 0, the
         default menu will be used.
   iId   is the id number of the prompt.
   pFunc is a pointer to the function to be linked.

 Return
   A logical indicating the success of the function. If an invalid menu
   pointer or id was specified, .f. will be returned.

 Description
   This function is used to assign an "on select function" to a prompt item.
   Menu handlers can then automatically execute this function when a prompt
   is selected. The address passed in the pFunc argument must point to a
   function with the following prototype:

     func logical MyFunc extern
     param value _MENU pMenu, value uint nId

   As a pointer to the menu, and the selected prompt's id is passed to the
   function, it is possible to write "generic" functions that perform
   different tasks depending on their arguments.

   The logical returned by the function to the menu handler can be used to
   indicate a certain result status allowing the menu handler to perform
   different actions.

 Example
   #define EXAMPLE_MENU
   #include example.hdr

   func logical FuncOne
   param value _MENU pMenu, value uint uId
   
   @ 12, 5 ?? "Hi, I'm FuncOne"
   
   return .t.
   endfunc
   
   // The "on select" function for the 2nd prompt
   //
   func logical FuncTwo
   param value _MENU pMenu, value uint uId
   
   @ 13, 5 ?? "Hi, I'm FuncTwo"
   
   return .t.
   endfunc
   
   // The "on select" function for the 3rd and 4th prompt
   //
   func logical FuncThreeFour
   param value _MENU pMenu, value uint uId
   
   // Perform different tasks, depending on the passed prompt id
   //
   do case
   case uId == 3
      @ 14, 5 ?? "Hi, I'm FuncThreeFour handling the 3rd prompt"
   case uId == 4
      @ 15, 5 ?? "Hi, I'm FuncThreeFour handling the 4th prompt"
   endcase
   
   return .t.
   endfunc
   
   proc Test_menusetfunc
   vardef
      _MENU pMenu
   enddef
   
   clear
   
   pMenu := menunew()
   
   menupromptnew( pMenu, 5, 5, " 1st prompt ", 1, .t., .t. )
   menupromptnew( pMenu, 6, 5, " 2nd prompt ", 2, .t., .t. )
   menupromptnew( pMenu, 7, 5, " 3rd prompt ", 3, .t., .t. )
   menupromptnew( pMenu, 8, 5, " 4th prompt ", 4, .t., .t. )
   
   // Assign "on select" functions to the prompts - note that the 3rd and
   // 4th prompt get assigned the same function
   //
   menusetfunc( pMenu, 1, &FuncOne )
   menusetfunc( pMenu, 2, &FuncTwo )
   menusetfunc( pMenu, 3, &FuncThreeFour )
   menusetfunc( pMenu, 4, &FuncThreeFour )
   
   repeat
      menuexecfunc( pMenu )
      waitms( 1000 )
   until .not. menusetnext( pMenu )
   
   menuclear( pMenu )
   
   endproc

   proc main
   Test_menusetfunc()
   endproc

See Also: menuexecfunc()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson