Seems there is an issue with updating Popup menus.
I'm trying to add/remove items dynamically destroying/recreating the menu with the same MenuID.
Code works as expected in PureBasic.
Thanks,
Code: Select all
; Original layout of menu. (Example code from the docs.)
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
; Let's add a new item
; Uncomment below block and Window won't be displayed in SB, but works OK in PB
; If IsMenu(0)
; FreeMenu(0)
; EndIf
;
; If CreatePopupMenu(0)
; MenuItem(1, "Cut")
; MenuItem(2, "Copy")
; MenuItem(3, "Paste")
; MenuBar()
; OpenSubMenu("Options")
; MenuItem(4, "Window...")
; MenuItem(5, "Gadget...")
; MenuItem(999, "New item...") ; New MenuItem added
; 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())
CompilerIf #PB_Compiler_OS <> #PB_OS_Web
Repeat
Event = WaitWindowEvent() ; check for window events
Until Event = #PB_Event_CloseWindow
CompilerEndIf
EndIf