Print Page | Close Window

How to load 2 commandbars from xml files

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=19810
Printed Date: 06 October 2024 at 2:22am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to load 2 commandbars from xml files
Posted By: xfsriddler
Subject: How to load 2 commandbars from xml files
Date Posted: 24 May 2012 at 3:54pm
I am having a difficult time finding any documentation on the
procedure for loading a toolbar from a saved xml file.
I need to have 2 toolbars on the bottom of my form that
are loaded from 2 different xml files.
Can you provide a simple example that
I can use to do this ?



Replies:
Posted By: SuperMario
Date Posted: 29 May 2012 at 2:45pm
Public Sub SaveXMLString(fileName As String)

Dim FreeF As Integer, sFile As String, sLayout As String
Dim XMLLayout As String

On Error Resume Next:

    'Creates a string containing the CommandBars layout, state, and settings.  The state options stored in the myStateOptions
    'object specifies which settings should be saved to the string.  To allow the XML file to be opened in the Designer Studio,
    'the profile name MUST be set to "DesignerFile"
    XMLLayout = CommandBars.SaveStateToXMLString("DesignerFile", myStateOptions)
    
    'XML string will be saved to a xml file.  Note that the file extension is .XML.  Opening a file
    'of type XML in a web browser will correctly format the XML sting.
    sFile = fileName
    FreeF = FreeFile
    Kill sFile
    Open sFile For Binary As #FreeF
    Put #FreeF, , XMLLayout
    Close #FreeF
End Sub

Public Sub LoadXMLString(fileName As String)

Dim FreeF As Integer, sFile As String, sLayout As String
Dim XMLLayout As String

On Error Resume Next:
                              
    'XML string will be loaded from the file.
    sFile = fileName
    FreeF = FreeFile
    XMLLayout = Space(FileLen(sFile))
    Open sFile For Binary As #FreeF
    Get #FreeF, , XMLLayout
    Close #FreeF
    On Error GoTo 0
    
    If (Not bSaveOnlyCustomized And bSerializeControls) Then
        'This is needed when the entire toolbar layout is loaded, not just user customization.
        'When the layout is loaded, the toolbars not present in the saved layout will not be deleted.
        'So you must manually remove all toolbars before loading a layout.
        'NOTE: The XML file must have been saved with bSaveOnlyCustomized = False And bSerializeControls = True
        'or the layout will not load properly.
        CommandBars.DeleteAll
    End If

    'Load the "DesignerFile" profile from the myXMLLayout string.  The state options stored in the
    'myStateOptions object specify how and what to restore of the Command Bars settings.
    CommandBars.LoadStateFromXMLString "DesignerFile", XMLLayout, myStateOptions
End Sub

Private Sub xmlFileLoad()
    Dim sFile As String

    With dlgCommonDialog
        .InitDir = App.Path
        .DialogTitle = "Load XML Layout"
        .CancelError = False
        'ToDo: set the flags and attributes of the common dialog control
        .Filter = "xml Files (*.xml)|*.xml"
        .ShowOpen
        If Len(.fileName) = 0 Then
            Exit Sub
        End If
        sFile = .fileName
    End With
    
    LoadXMLString (sFile)
    
End Sub

Private Sub xmlFileSave()
    Dim sFile As String
    
    With dlgCommonDialog
        .InitDir = App.Path
        .DialogTitle = "Save XML Layout"
        .CancelError = False
        'ToDo: set the flags and attributes of the common dialog control
        .Filter = "xml Files (*.xml)|*.xml"
        .ShowSave
        If Len(.fileName) = 0 Then
            Exit Sub
        End If
        sFile = .fileName
    End With
    
    SaveXMLString (sFile)

End Sub


Posted By: xfsriddler
Date Posted: 29 May 2012 at 2:55pm
thanks, but how would I load 2 different tool bars on the same
form ?



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net