Menu in container
Posted: Sun May 16, 2004 12:29 am
				
				- Sparkie (who gave me the solution)
- Eddy
This code could be improved: find a way to maintain the focus
			- Eddy
This code could be improved: find a way to maintain the focus
Code: Select all
Enumeration 
   #WIN
   #CONTAINER
   #MENU
   #CONTAINER_2
   #MENU_2
EndEnumeration 
; ==================
; Convert container to fake window (can contain a menu)
; ==================
Procedure.l ContainerWindowID(containerID)
      setwindowlong_(GadgetID(containerID),#GWL_STYLE,getwindowlong_(GadgetID(containerID),#GWL_STYLE)|#WS_POPUP|#BS_OWNERDRAW)
      ProcedureReturn GadgetID(containerID)
EndProcedure 
; ==================
; Example
; ==================
If OpenWindow(#WIN, 0, 0, 500, 300,  #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "Menu in container")   
   If CreateGadgetList(WindowID()) 
      ContainerGadget(#CONTAINER,5,5, 450, 40)         
         *m1=CreateMenu(#MENU, ContainerWindowID(#CONTAINER)) 
         MenuTitle("&Project") 
         MenuItem(1,"&New   Ctrl+N") 
         MenuItem(2,"&Open...   Ctrl+O")       
      CloseGadgetList()   
      
      ContainerGadget(#CONTAINER_2,5,50, 450, 40,#PB_CONTAINER_RAISED)         
         *m2=CreateMenu(#MENU_2, ContainerWindowID(#CONTAINER_2)) 
         MenuTitle("&Compile") 
         MenuItem(3,"&Run") 
         MenuItem(4,"&Debug")       
      CloseGadgetList()       
   EndIf   
EndIf 
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow 
End