CreatePopupMenu()

Syntax

Result = CreatePopupMenu(#Menu)
Description
Creates a new empty popup menu.

Parameters

#Menu A number to identify the new menu. #PB_Any can be used to auto-generate this number.

Return value

Nonzero if the menu was successfully created, zero otherwise. If #PB_Any was used for the #Menu parameter then the generated number is returned on success.

Remarks

To create a popup menu with support for images, use CreatePopupImageMenu().

Once created, this menu becomes the current menu for further item additions. It's now possible to use functions such as MenuTitle(), MenuItem(), MenuBar(), OpenSubMenu() to populate the menu.

DisplayPopupMenu() can be used to display this popup menu at any position on the screen.

To handle menu events, use BindEvent(), EventWindow() and EventMenu().

Example

  If CreatePopupMenu(0)
    MenuItem(1, "Cut")
    MenuItem(2, "Copy")
    MenuItem(3, "Paste")
    MenuBar()
    OpenSubMenu("Options")
      MenuItem(4, "Window...")
      MenuItem(5, "Gadget...")
    CloseSubMenu()
    MenuBar()
    MenuItem( 6, "Quit")
  EndIf
    
  Procedure GadgetEvents()
    If EventGadget() = 0 And EventType() = #PB_EventType_RightClick
      DisplayPopupMenu(0, WindowID(0))
    EndIf
  EndProcedure
    
  Procedure MenuEvents()
    Debug EventMenu()  ; To see which menu has been selected
  EndProcedure
  
  ;
  ; We just have to open a window and see when an event happen on the menu
  ;
  If OpenWindow(0, 100, 100, 300, 260, "SpiderBasic - PopupMenu Example")
  
    ListIconGadget(0, 10, 10, 280, 240, "Tools", 200)
      AddGadgetItem(0, -1, "Hammer")
      AddGadgetItem(0, -1, "Screwdriver")
          
    BindEvent(#PB_Event_Menu, @MenuEvents())
    BindEvent(#PB_Event_Gadget, @GadgetEvents())
  EndIf

See Also

CreatePopupImageMenu(), DisplayPopupMenu(), CreateMenu(), CreateImageMenu(), FreeMenu(), MenuTitle(), MenuItem(), MenuBar(), OpenSubMenu()

Supported OS

All

<- CreatePopupImageMenu() - Menu Index - DisableMenuItem() ->