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 properly, see the description of following functions:
WaitWindowEvent() (alternatively WindowEvent())
EventWindow()
EventMenu()

Example

  If OpenWindow(0, 200, 200, 200, 120, "Popup-Menu Example")
  
    If CreatePopupMenu(0)      ; creation of the pop-up menu begins...
      MenuItem(1, "Open")      ; You can use all commands for creating a menu
      MenuItem(2, "Save")      ; just like in a normal menu...
      MenuItem(3, "Save as")
      MenuItem(4, "Quit")
      MenuBar()
      OpenSubMenu("Recent files")
        MenuItem(5, "PureBasic.exe")
        MenuItem(6, "Test.txt")
      CloseSubMenu()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()     ; check for window events
      
      Select Event
        Case #PB_Event_RightClick       ; right mouse button was clicked =>
          DisplayPopupMenu(0, WindowID(0))  ; now display the popup-menu
          
        Case #PB_Event_Menu        ; an item of the popup-menu was clicked
          Select EventMenu()       ; get the clicked menu item...
            Case 1 : Debug "Menu: Open"
            Case 2 : Debug "Menu: Save"
            Case 3 : Debug "Menu: Save as"
            Case 4 : End
            Case 5 : Debug "Menu: PureBasic.exe"
            Case 6 : Debug "Menu: Text.txt"
          EndSelect
          
      EndSelect
      
    Until Event = #PB_Event_CloseWindow
  EndIf

See Also

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

Supported OS

All

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