J'ai fait un petit test avec ce fichier que j'ai nommé ui0.xml
Code : Tout sélectionner
<?xml version="1.0" encoding="UTF-8"?>
<dialogs>
<window name="window_0" flags="#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered" width="800" height="600" text="My application" id="#mf"/>
</dialogs>
Il ouvre une fenêtre de taille 800x600 centrée. Je n'ai pas ajouté d'autre gadget pour ne pas surcharger ce test.
■ Mise en DataSection.
Code : Tout sélectionner
DataSection
XMLDialog:
IncludeBinary "ui0.xml"
XMLDialog_EOF:
EndDataSection
Code : Tout sélectionner
XML.s = PeekS(?XMLDialog, ?XMLDialog_EOF - ?XMLDialog, #PB_UTF8)
https://www.purebasic.com/french/docume ... index.html
■ Le code exemple.
Code : Tout sélectionner
#XML = 0
#Dialog = 0
Runtime Enumeration Window
#mf
EndEnumeration
;Plan de l'application
Declare Start()
Declare Exit()
Start()
Procedure Start()
;Lecture du fichier XML en DataSection.
;Pour cette démo mon fichier XML (ui0.xml) est au format UTF-8
Protected XML.s = PeekS(?XMLDialog, ?XMLDialog_EOF - ?XMLDialog, #PB_UTF8) ;ou #PB_ASCII si fichier au format ASCII
;Chargement de l'interface de dialogue
If CatchXML(#Xml, @XML, StringByteLength(XML), 0, #PB_UTF8) And XMLStatus(#Xml) = #PB_XML_Success
;Créer l'interface utilisateur
CreateDialog(#Dialog)
;Ouvrir la fenetre nommée : "window_0"
If OpenXMLDialog(#Dialog, #Xml, "window_0")
;Déclencheurs evenementiels
BindEvent(#PB_Event_CloseWindow, @Exit())
Repeat : WaitWindowEvent() : ForEver
Else
Debug "Dialog creation erreur: " + DialogError(#Dialog)
EndIf
Else
Debug "Erreur lié à l'encodage du fichier UTF-8 avec BOM ou ASCII"
Debug "XML erreur à la ligne" + XMLErrorLine(#Xml) + ": " + XMLError(#Xml)
EndIf
EndProcedure
Procedure Exit()
End
EndProcedure
DataSection
XMLDialog:
IncludeBinary "ui0.xml"
XMLDialog_EOF:
EndDataSection