Page 1 of 1

Create menu items after window opened

Posted: Tue Aug 12, 2008 3:36 am
by superjacent
Is it possible to create menu items after the initial window/menu creation routine.

What I'm wanting to do, for tutorial purposes, is create or add menu items to an already created menu structure ie 'recent folders' menu item under the 'File' menu.

If this is possible, any chance of a quick snippet to get me started?

A thought that is crossing my mind is that I could remove the entire menu structure and recreate the new menu structure (I'm thinking aloud now). I'm assuming it is possible to dynamically remove a menu structure.

Any help appreciated.

Posted: Tue Aug 12, 2008 7:05 pm
by Marco2007
Something like that?

Code: Select all

Global recent1.s="first Document" 
Global recent2.s="second Document" 
Global recent3.s="" 
Global recent4.s="" 

Procedure recent() 
  If CreateMenu(0, WindowID(0)) 
    MenuTitle("Menu") 
    MenuItem(1, "first") 
    MenuItem(2, "second") 
    MenuItem(3, "last") 
    OpenSubMenu("recent") 
    If recent1<>"": MenuItem(4, recent1): EndIf 
    If recent2<>"": MenuItem(5, recent2): EndIf 
    If recent3<>"": MenuItem(6, recent3): EndIf 
    If recent4<>"": MenuItem(7, recent4): EndIf 
    CloseSubMenu() 
EndIf 
EndProcedure 


If OpenWindow(0, 0, 0, 200, 200, "",  #PB_Window_SystemMenu) And CreateGadgetList(WindowID(0)) 
  ButtonGadget(0, 50, 50, 100, 20, "recent") 
  recent() 
EndIf 

Repeat 
  event=WaitWindowEvent():Select event: Case #PB_Event_Gadget: Select EventGadget() 
    Case 0 
      recent1.s="first Document" 
      recent2.s="second Document" 
      recent3.s="third Document" 
      recent4.s="" 
      If IsMenu(0) 
       FreeMenu(0) 
      EndIf 
      recent() 
  EndSelect: EndSelect  
Until event=#PB_Event_CloseWindow
lg
marco

Posted: Wed Aug 13, 2008 1:36 am
by superjacent
I can see that in your example, you are effectively re-creating the whole menu structure after deleting it.

I've got something to work with now, thanks.