Page 1 of 1

Menu in container

Posted: Sun May 16, 2004 12:29 am
by eddy
- Sparkie (who gave me the solution)
- 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

Posted: Mon May 17, 2004 12:37 am
by Sparkie
Sorry to say the code crashes here on PB 3.90 SP1
PureBasic41334045.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
I had similar problems when I was first experimenting with your initial request for container menus.. SetWindowLong_() procedure caused crash after crash. That forced me to create my own container.

Posted: Mon May 17, 2004 2:00 am
by eddy
It works with PB 3.81
perhaps a bug

Posted: Mon May 17, 2004 8:01 am
by Jon
Yup same problem here with PB 3.90

Posted: Sat May 22, 2004 12:27 am
by eddy
Finaly sparkie gave a simplier solution:

viewtopic.php?t=10903