Dialog XML en DataSection

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
falsam
Messages : 7244
Inscription : dim. 22/août/2010 15:24
Localisation : IDF (Yvelines)
Contact :

Dialog XML en DataSection

Message par falsam »

J'ai lu quelques part sur ce forum qu'il n'était pas facile de mettre un fichier de dialogue XML dans la DataSection.

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>
Ce fichier est saisie avec NotePad ++ au format UTF-8

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
■ Lecture du fichier dans une variable string.

Code : Tout sélectionner

XML.s = PeekS(?XMLDialog, ?XMLDialog_EOF - ?XMLDialog, #PB_UTF8)
La suite du code est classique est fait référence à la bibliothéque Dialog
:arrow: 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
Dernière modification par falsam le jeu. 19/juil./2018 13:39, modifié 1 fois.
Configuration : Windows 11 Famille 64-bit - PB 6.03 x64 - AMD Ryzen 7 - 16 GO RAM
Vidéo NVIDIA GeForce GTX 1650 Ti - Résolution 1920x1080 - Mise à l'échelle 125%
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: Dialog XML en DataSection

Message par Kwai chang caine »

Ca marche nickel merci 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Avatar de l’utilisateur
microdevweb
Messages : 1800
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Dialog XML en DataSection

Message par microdevweb »

Merci falsam pour cet exemple
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
Micoute
Messages : 2522
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: Dialog XML en DataSection

Message par Micoute »

Merci falsam pour cet exemple, je l'ai modifié en y mettant mes propres constantes et ça fonctionne très bien.
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 5.73 PB 6.00 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Répondre