ich benutze die Dialog Library um GUIs über XML zu erstellen. Das klappt zum Beispiel für Buttons, Checkboxes etc. ganz gut.
Code: Alles auswählen
<button name="btExample" text="Example" onevent="On_btExample_Event()"/>
Danke und Grüße
Code: Alles auswählen
<button name="btExample" text="Example" onevent="On_btExample_Event()"/>
Code: Alles auswählen
EnableExplicit
Procedure ProcessGadgets(Dialog, Window, XmlNode)
Protected Name.s
Protected ImgSrc.s
Protected Img
Protected ChildNode = ChildXMLNode(XmlNode)
While ChildNode <> 0
If ExamineXMLAttributes(ChildNode)
Name = ""
ImgSrc = ""
While NextXMLAttribute(ChildNode)
Select LCase(XMLAttributeName(ChildNode))
Case "name"
Name = XMLAttributeValue(ChildNode)
Case "src"
If Name
ImgSrc = XMLAttributeValue(ChildNode)
If FileSize(ImgSrc) > -1
Img = LoadImage(#PB_Any, ImgSrc)
If Img
SetGadgetState(DialogGadget(Dialog, Name), ImageID(Img))
FreeImage(Img)
EndIf
EndIf
EndIf
EndSelect
Wend
EndIf
If XMLChildCount(ChildNode)
ProcessGadgets(Dialog, Window, ChildNode)
EndIf
ChildNode = NextXMLNode(ChildNode)
Wend
EndProcedure
Procedure OpenXMLDialog2(Dialog, Xml, Name.s, x, y, Width, Height, ParentID)
Protected Result = OpenXMLDialog(Dialog, Xml, Name.s, x, y, Width, Height, ParentID)
If Result
ProcessGadgets(Dialog, DialogWindow(Dialog), MainXMLNode(Xml))
EndIf
ProcedureReturn Result
EndProcedure
Macro OpenXMLDialog(Dialog, Xml, Name, x=0, y=0, Width=0, Height=0, ParentID=0)
OpenXMLDialog2(Dialog, Xml, Name, x, y, Width, Height, ParentID)
EndMacro
; ###############
; # Example:
; ###############
Define XML.s = "<window id='#PB_Any' name='test' text='Dialog example' minwidth='auto' minheight='auto' flags='#PB_Window_ScreenCentered'>" +
" <image id='image1' name='image1' src='" + #PB_Compiler_Home + "/examples/sources/Data/Geebee2.bmp' />" +
"</window>"
#Dialog = 0
#Xml = 0
If ParseXML(#Xml, XML) And XMLStatus(#Xml) = #PB_XML_Success
If CreateDialog(#Dialog) And OpenXMLDialog(#Dialog, #Xml, "test")
RefreshDialog(#Dialog) ; important!
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Else
Debug "Dialog error: " + DialogError(#Dialog)
EndIf
EndIf