BindMenuEvent()

语法

BindMenuEvent(#Menu, MenuItem, @Callback())
概要
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 unbinded with UnbindMenuEvent().

参数

#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.

返回值

无.

示例

  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

参阅

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

已支持操作系统

所有

Menu Index - CloseSubMenu() ->