Menu in container

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Menu in container

Post 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
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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.
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

It works with PB 3.81
perhaps a bug
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Jon
User
User
Posts: 20
Joined: Sat Apr 26, 2003 9:12 am
Location: New Zealand
Contact:

Post by Jon »

Yup same problem here with PB 3.90
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Post by eddy »

Finaly sparkie gave a simplier solution:

viewtopic.php?t=10903
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply