CreateMenu()

Syntax

Result = CreateMenu(#Menu, WindowID)
Description
Creates a new empty menu on the given window.

Parameters

#Menu A number to identify the new menu. #PB_Any can be used to auto-generate this number.
WindowID The window for the new menu. It can be obtained using the WindowID() function.

Return value

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

Remarks

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

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.

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

Example

  Procedure MenuEvents()
    Debug "Menu item selected: " + EventMenu()
  EndProcedure
    
  If OpenWindow(0, 200, 200, 200, 100, "Menu Example")
    If CreateMenu(0, WindowID(0))    ; menu creation starts....
      MenuTitle("Project")
      MenuItem(1, "Open"    + #TAB$ + "Shift+O")
      MenuItem(2, "Save"    + #TAB$ + "Shift+S")
      MenuItem(3, "Save as" + #TAB$ + "Shift+A")
      MenuItem(4, "Close"   + #TAB$ + "Shift+C")
    EndIf
    
    BindEvent(#PB_Event_Menu, @MenuEvents())
  EndIf

See Also

CreateImageMenu(), CreatePopupMenu(), CreatePopupImageMenu(), FreeMenu(), MenuTitle(), MenuItem(), MenuBar(), OpenSubMenu()

Supported OS

All

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