BindMenuEvent()

Syntax

BindMenuEvent(#Menu, MenuItem, @Callback())
Description
Bind a menu event to a callback. It's an additional way to handle events in PureBasic, which works without problem with the regulars WindowEvent() / WaitWindowEvent() commands. A menu event can be unbound with UnbindMenuEvent().

Parameters

#Menu The menu to bind the event to.
MenuItem The menu item within the menu to bind the event to.
@Callback() The callback procedure to call when the event occurs. It has to be declared like this:
  Procedure EventHandler()
    ; Code
  EndProcedure
Regular functions like EventGadget(), EventWindow(), EventMenu(), EventType() and EventData() are available within the callback to get more information about the event.

Note: WindowEvent() and WaitWindowEvent() should never be called from inside the callback or the program can be locked or have wrong behavior.

Return value

None.

Example

  Procedure TestHandler()
    Debug "Test menu event"
  EndProcedure

  Procedure QuitHandler()
    Debug "Quit menu event"
    End
  EndProcedure

  OpenWindow(0, 100, 100, 200, 50, "Click test", #PB_Window_SystemMenu)

  CreateMenu(0, WindowID(0))
    MenuTitle("File")
      MenuItem(0, "Test")
      MenuItem(1, "Quit")

  BindMenuEvent(0, 0, @TestHandler())
  BindMenuEvent(0, 1, @QuitHandler())

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow

See Also

BindGadgetEvent(), BindMenuEvent(), UnbindEvent(), WindowEvent(), WaitWindowEvent()

Supported OS

All

Menu Index - CloseSubMenu() ->