Create Menus using #PB_Any? [Solved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 4260
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Create Menus using #PB_Any? [Solved]

Post by skywalk »

Hi,
Can I apply #PB_Any to menus also?
http://www.purebasic.fr/english/viewtop ... 13&t=41118

I eventually want to programmatically create my menus using DataSections and Read.s. Looks like I must predefine the MenuItem IDs.
Converting some apps from VB6 and I have over 150 menu items in some.

Is the #PB_Any behavior below correct?
It seems to just report a #True condition instead of a unique Gadget/Menu ID?

Code: Select all

If OpenWindow(0, 50, 50, 200, 50, "Window_0", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
  If CreateMenu(0, WindowID(0))
    r1 = MenuTitle("&File")
    r2 = MenuItem(#PB_Any, "&Open")
    r3 = MenuItem(#PB_Any, "Close")
    r4 = MenuBar()
    MenuItem(#PB_Any, "Exit")
    MenuBar()
    MenuItem(#PB_Any, "Really Exit!")
    OpenSubMenu("SubMenu")      
  EndIf
EndIf
Debug r1  
Debug r2  
Debug r3  
Debug r4
    
Repeat
  Select WaitWindowEvent()
  Case #PB_Event_CloseWindow
    Break
  EndSelect  
ForEver
Last edited by skywalk on Sat Nov 24, 2012 5:44 pm, edited 2 times in total.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Create Menus using #PB_Any?

Post by ts-soft »

there is no #PB_Any support for Menu!
Small workaround:

Code: Select all

Procedure AnyMenuItem(text.s)
  Static MenuItemID
  
  MenuItemID + 1
  MenuItem(MenuItemID, text)
  ProcedureReturn MenuItemID
EndProcedure

If OpenWindow(0, 50, 50, 200, 50, "Window_0", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar)
  If CreateMenu(0, WindowID(0))
    MenuTitle("&File")
    r1 = AnyMenuItem("&Open")
    r2 = AnyMenuItem("Close")
    MenuBar()
    r3 = AnyMenuItem("Exit")
    MenuBar()
    r4 = AnyMenuItem("Really Exit!")
    OpenSubMenu("SubMenu")
  EndIf
EndIf

Debug r1
Debug r2
Debug r3
Debug r4

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
  EndSelect
ForEver
User avatar
skywalk
Addict
Addict
Posts: 4260
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Create Menus using #PB_Any?

Post by skywalk »

Thanks ts-soft for the confirmation and the suggestion of Static!
This will speed me along. :)
Trying not to use APIs and GetMenu_~ stuff...

I'll add this topic to my Feature Requests...
Post Reply