Page 1 of 1

Create Menus using #PB_Any? [Solved]

Posted: Tue Mar 09, 2010 6:21 pm
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

Re: Create Menus using #PB_Any?

Posted: Tue Mar 09, 2010 6:38 pm
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

Re: Create Menus using #PB_Any?

Posted: Tue Mar 09, 2010 7:07 pm
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...