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 - menuexecfunc() execute the current prompt's function http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 menuexecfunc()      Execute the current prompt's function
------------------------------------------------------------------------------
 Declaration
   menu.hdr

 Syntax
   func logical menuexecfunc extern
   param value _MENU pMenu

 Arguments
   pMenu is the pointer to a previously created menu system. If 0, the
         default menu will be used.

 Return
   A logical containing the result of the executed function, .t. if no
   function is linked to the current prompt, or .f. if an invalid menu
   pointer was specified.

 Description
   This function executes the function associated to the current prompt.

   It is possible to assign an "on select function" to a prompt item.
   Menu handlers can then automatically execute the "on select function" by
   calling menuexecfunc() when a prompt is selected.

   The "on select function" must have 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

   // The "on select" function for the 1st prompt
   //
   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_menuexecfunc
   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_menuexecfunc()
   endproc

See Also: menusetfunc()

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