Build a popup-submenu with a variable number of entries?

Just starting out? Need help? Post your questions and find answers here.
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Build a popup-submenu with a variable number of entries?

Post by Lebostein »

How I can do that? For example a dynamic list with the opened files? There is no DeleteMenuItem() function...
Or I have to rebuild the complete popup menu every time before I show it? But how I delete the complete popup menu after disappearing? There is no event for "popup menu is hidden now"
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Build a popup-submenu with a variable number of entries?

Post by RSBasic »

Crossplattform resultion: You can recreate your menu:

Code: Select all

EnableExplicit

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(1, 10, 10, 100, 20, "CHange menu", 0)
  If CreatePopupMenu(1)
    MenuItem(1, "Hello")
    MenuItem(2, "Hi")
    MenuItem(3, "Hola")
  EndIf
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_RightClick
        DisplayPopupMenu(1, WindowID(0))
      Case #PB_Event_Gadget
        Select EventGadget()
          Case 1
            If CreatePopupMenu(1)
              MenuItem(1, "Hello")
              MenuItem(2, "Hi")
            EndIf
        EndSelect
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
\\Edit:
If WinAPI: RemoveMenu_()
Image
Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Build a popup-submenu with a variable number of entries?

Post by RSBasic »

Lebostein wrote:There is no event for "popup menu is hidden now"

Code: Select all

EnableExplicit

Procedure WinCallback(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_UNINITMENUPOPUP
      Debug "PopupMenu is now hidden."
  EndSelect
 
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If CreatePopupMenu(1)
    MenuItem(1, "Hallo")
    MenuItem(2, "Welt")
  EndIf
 
  SetWindowCallback(@WinCallback())
 
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_RightClick
        DisplayPopupMenu(1, WindowID(0))
      Case #PB_Event_CloseWindow
        End
    EndSelect
  ForEver
EndIf
Image
Image
Fred
Administrator
Administrator
Posts: 16686
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Build a popup-submenu with a variable number of entries?

Post by Fred »

Recreating the menu is the way to go
Post Reply