PureBasic Forum
http://forums.purebasic.com/english/

Dialog with Menu and Statusbar
http://forums.purebasic.com/english/viewtopic.php?f=12&t=75596
Page 1 of 1

Author:  Mesa [ Thu Jun 25, 2020 5:17 pm ]
Post subject:  Dialog with Menu and Statusbar

Encapsulate your dialog inside a vbox with 2 <empty> as header and footer, like that:
Code:
;XML from DDEsign0r
;Encapsulate your dialog inside a vbox like that <vbox spacing='0' expand='item:2'>
;Add a header named "menu" like that <empty height='6' name='menu'/>
;Add your dialog
;Add a footer named statusbar like that <empty height='32' name='statusbar'/>
XML$ = ~"<dialogs>\n"
XML$ + ~"  <window flags='#PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget' text='titre' minheight='100' name='window_1'>\n"
XML$ + ~"    <vbox spacing='0' expand='item:2'>\n"
XML$ + ~"      <empty height='6' name='menu'/>\n"
XML$ + ~"      <button name='button_1'/>\n"
XML$ + ~"      <empty height='32' name='statusbar'/>\n"
XML$ + ~"    </vbox>\n"
XML$ + ~"  </window>\n"
XML$ + ~"</dialogs>\n"
XML$ + ~""

;Get Menu height and statusbar height
MenuH=MenuHeight()
; Debug MenuH
DummyWindow      = OpenWindow(#PB_Any,0,0,10,10,"",#PB_Window_Invisible)
If DummyWindow
  DummyStatusBar   = CreateStatusBar(#PB_Any, WindowID(DummyWindow))
  If DummyStatusBar                                                                        
    StatusbarH= StatusBarHeight(DummyStatusBar)
  EndIf
  CloseWindow(DummyWindow)
EndIf
; Debug StatusbarH

;Update header and footer
; XML$=ReplaceString(XML$,"<empty height='6' name='menu'/>","<empty height='"+Str(MenuH)+"' name='menu'/>")            
XML$=ReplaceString(XML$,"<empty height='32' name='statusbar'/>","<empty height='"+Str(StatusbarH+MenuH)+"' name='statusbar'/>")


;Let's create our dialog
#Dialog = 0
#Xml = 0

If ParseXML(#Xml, XML$) And XMLStatus(#Xml) = #PB_XML_Success
 
  If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "window_1")
    hwd=DialogWindow(#Dialog)
;     Debug GetWindowTitle(hwd)
;     Debug DialogGadget(#Dialog, "button_1")
   
   
    ;Let's create a menu
    If CreateMenu(0, WindowID(hwd))   
      MenuTitle("File")
      MenuItem(1, "New"+Chr(9)+"Ctrl+N")
      MenuItem(2, "Open"+Chr(9)+"Ctrl+O")
      MenuBar()
      MenuItem(3, "Quit")
    EndIf
   
    ;Let's create a statusbar
    If CreateStatusBar(0, WindowID(hwd))
      AddStatusBarField(110)
      AddStatusBarField(150)
      AddStatusBarField(#PB_Ignore)
      AddStatusBarField(300)
    EndIf
    StatusBarText(0, 0, "Field normal")
    StatusBarText(0, 1, "Field2", #PB_StatusBar_BorderLess)
    StatusBarText(0, 2, "Field3", #PB_StatusBar_Right)
    StatusBarText(0, 3, "Field4", #PB_StatusBar_Center)
   
   
    ;Loop as usual
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_Menu   
          Select EventMenu()   
            Case 3 : End
          EndSelect
         
        Case #PB_Event_CloseWindow
          Quit = 1
         
      EndSelect
    Until Quit = 1
   
  Else 
    Debug "Error -Dialog- : " + DialogError(#Dialog)
  EndIf
Else
  Debug "Error XML : " + XMLError(#Xml) + " (Line: " + XMLErrorLine(#Xml) + ")"
EndIf


M.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/