Create menu items after window opened

Just starting out? Need help? Post your questions and find answers here.
superjacent
User
User
Posts: 27
Joined: Mon Oct 01, 2007 1:38 pm
Location: Melbourne, Australia
Contact:

Create menu items after window opened

Post 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.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post 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
PureBasic for Windows
superjacent
User
User
Posts: 27
Joined: Mon Oct 01, 2007 1:38 pm
Location: Melbourne, Australia
Contact:

Post 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.
Post Reply