Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - How to load 2 commandbars from xml files
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to load 2 commandbars from xml files

 Post Reply Post Reply
Author
Message
xfsriddler View Drop Down
Groupie
Groupie


Joined: 22 February 2010
Location: United States
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote xfsriddler Quote  Post ReplyReply Direct Link To This Post Topic: How to load 2 commandbars from xml files
    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 ?
Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
xfsriddler View Drop Down
Groupie
Groupie


Joined: 22 February 2010
Location: United States
Status: Offline
Points: 16
Post Options Post Options   Thanks (0) Thanks(0)   Quote xfsriddler Quote  Post ReplyReply Direct Link To This Post Posted: 29 May 2012 at 2:55pm
thanks, but how would I load 2 different tool bars on the same
form ?
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.203 seconds.