6 Replies Latest reply on Jan 23, 2009 10:29 PM by arash.khoddamy

    ProcessBook Toolbar Organizations

    arash.khoddamy

      Hi,

       

      I have written three Toolbar add-Ins for ProcessBook. As part of the requirements I have to recreate the toolbars each time ProcessBook starts. (We do this since users hide them and do not know how to bring them back) But at this point they show one below each other and take valuable screen space. I would like to be able to, on startup, place one toolbar beside the other as they do not take the full length of the screen.

       

      Curretly they show like:

       

      Toolbar1

      Toolbar2

      Toolbar3

       

      I want them to load like this:
       

      Toobar1 Toolbar2 Toolbar3

       

       

       

      Thanks

       

       

       

      Arash

       

       

        • Re: ProcessBook Toolbar Organizations

          Hello,

           


          When ProcessBook loads it checks a couple of important configuration file, Procbook.ini and PBToolbarConfig.ini.  In your case I would home in on PBToolBarConfig.ini as when ProcessBook is closed, it dumps the toolbars open and their position so next time it loads it reads again from this file.

           

          The file only comes into play during load/unload so in your particular case when a toolbar is loaded you need to check for any of your other toolbars, check its position and place next to it.  If I get some spare time I will take a look but you may get a quicker answer from OSI or even a Windows/Office forum as the concept of toolbars is not OSI specific.

           

           

          • Re: ProcessBook Toolbar Organizations
            andreas

            Hi,

             

            there is an example in the PIDEMO.PIW that gets installed with ProcessBook. The display VBA Utility Examples features the code to place the Toolbars.

             

            hope this helps,

             

               andreas

              • Re: ProcessBook Toolbar Organizations

                Edit: Apologies, found the examples

                 

                Andreas...couldn't find the example, but I created an example too, it will place a command button next to the full screen toolbar (providing it is displayed).

                
                

                Const cCommandBarID As String = "RJK Solutions", cBtn1Sub As String = "MySub"
                 
                Sub CreateCM()
                    Dim cbBar As PBCommandBar, cbCtrl As PBCommandBarControl
                    
                    DeleteCM
                    
                    Set cbBar = Application.CommandBars.Add(cCommandBarID, pbcBartop)
                    Set cbCtrl = cbBar.Controls.Add(Type:=msoControlButton)
                    With cbCtrl
                        .FaceId = 59            'Smiley Face Id
                        .OnAction = cBtn1Sub
                        .Style = msoButtonIcon
                    End With
                    With cbBar
                        .Visible = True
                        .Position = pbBarTop
                        .Left = Application.CommandBars.Item("Full Screen ToolBar").Left + Application.CommandBars.Item("Full Screen ToolBar").Width
                        .Top = Application.CommandBars.Item("Full Screen ToolBar").Top
                    End With
                    
                    Set cbBar = Nothing
                    Set cbCtrl = Nothing
                    
                End Sub
                 
                Sub DeleteCM()
                    Dim cbBar As PBCommandBar
                    
                    On Error Resume Next
                    Set cbBar = Application.CommandBars.Item(cCommandBarID)
                    cbBar.Delete
                    On Error GoTo 0
                    Set cbBar = Nothing

                End Sub

                  • Re: ProcessBook Toolbar Organizations
                    andreas

                    Hi,

                     

                    got the code from the example (pidemo.piw) - it optimizes the arrangement of the toolbars:

                    
                    

                    Option Explicit

                    Private Sub CommandButton1_Click()
                    Call ConfigureToolBars
                    End Sub

                     

                    Public Sub ConfigureToolBars()

                        'Determine which toolbars other than menubars are visible.  Put them in a list.
                        'Undock and hide all bars.  Make each of them one row high.

                        'Call the routinte to dock all menubars at the top of the application
                        'Show the active menubar

                        'Get the width of the menubar.  This is the width of the application.
                       
                        'Set the current vertical postion equal to the height of the menubar
                        'Set the current horizontal position equal to 0
                        'Call the method to dock the rest of the toolbars.

                        ReDim ToolBarArray(-1 To -1) As PBCommandBar
                        ReDim MenuBarArray(-1 To -1) As PBCommandBar
                        Dim cbBars As PBCommandBars
                        Dim cbBar As PBCommandBar
                       
                        Set cbBars = Application.CommandBars
                       
                        For Each cbBar In cbBars
                            If IsMenuBar(cbBar) Then
                                Call AddBar(cbBar, MenuBarArray)
                            Else
                                If cbBar.Visible Then
                                    Call AddBar(cbBar, ToolBarArray)
                                End If
                            End If
                            cbBar.Position = pbBarFloating
                            cbBar.Height = 10
                        Next cbBar
                       
                        Call DockMenuBars(MenuBarArray)
                        Call ClearArray(MenuBarArray)
                        cbBars.ActiveMenuBar.Visible = True
                       
                        Call DockToolBars(cbBars.ActiveMenuBar.Width, cbBars.ActiveMenuBar.Height, ToolBarArray)
                       
                        Call ClearArray(ToolBarArray)
                    End Sub

                     

                    Public Sub DockMenuBars(BarsArray() As PBCommandBar)
                        'Dock all menubars at the top of the application
                        Dim nUBound As Long
                        Dim i As Integer
                        nUBound = UBound(BarsArray)
                       
                        For i = 0 To nUBound
                            BarsArray(i).Position = pbBarTop
                            BarsArray(i).Top = 0
                            BarsArray(i).Left = 0
                        Next i
                       
                    End Sub

                    Public Sub DockToolBars(nMaxHPos As Long, nVPos As Long, BarsArray() As PBCommandBar)
                        'While there are still undocked toolbars do
                            'Determine the largest undocked toolbar that will fit in the remainder of the current row.
                            'If there is not enough room in the current row then
                                'Increment the current vertical position by the height of a docked toolbar
                                'Set the current position equal to 0
                            'EndIf
                            'Dock the toolbar with the largest width at the current horizontal and vertical position
                            'Increment the current horizontal position by the width of the toolbar.
                        'EndWhile
                       
                        Dim bFits As Boolean
                        Dim nUBound As Long
                        Dim cbBar As PBCommandBar
                        Dim nTargetWidth As Long
                        Dim nHPos As Long
                        Dim barWidth As Long
                        Dim barHeight As Long
                       
                        nUBound = UBound(BarsArray)
                       
                        'InitializenHPos to nMaxHPos to force starting on a new row.
                        nHPos = 0

                        While True
                           
                            nTargetWidth = nMaxHPos - nHPos
                            bFits = False
                            Set cbBar = GetUndockedBarForTargetWidth(nTargetWidth, BarsArray, bFits)
                            If cbBar Is Nothing Then
                                'All bars are docked
                                Exit Sub
                            End If
                           
                            'DEBUGGING ONLY
                            'If cbBar.Name = "VBA Toolbar" Then
                            '    Stop
                            'End If
                       
                            If Not bFits Then
                                nVPos = nVPos + barHeight

                                nHPos = 0
                            End If
                           
                            cbBar.Visible = True
                            cbBar.Position = pbBarTop
                            barWidth = cbBar.Width
                            barHeight = cbBar.Height
                            cbBar.Left = nHPos
                            cbBar.Top = nVPos
                           
                            nHPos = nHPos + barWidth

                           
                            DoEvents
                           
                        Wend

                    End Sub

                     

                    Public Function GetUndockedBarForTargetWidth(nTargetWidth As Long, BarsArray() As PBCommandBar, bFits As Boolean) As PBCommandBar
                        'Find the undocked bar that a width that is closest to but not greater than the target width
                        'If there is no undocked bar that is less than the target width then the bar with the largest width is returned.
                        Dim nSelectedWidth As Long
                        Dim nWidth As Long
                        Dim nUBound As Long
                        Dim i As Integer

                        nUBound = UBound(BarsArray)
                        bFits = False
                        nSelectedWidth = -1
                        Set GetUndockedBarForTargetWidth = Nothing
                       
                        For i = 0 To nUBound
                            nWidth = BarsArray(i).Width
                            If BarsArray(i).Position = pbBarFloating And nWidth > nSelectedWidth And nWidth <= nTargetWidth Then
                                Set GetUndockedBarForTargetWidth = BarsArray(i)
                                nSelectedWidth = nWidth
                                bFits = True
                            End If
                        Next i
                       
                        If bFits Then
                            Exit Function
                        End If

                        For i = 0 To nUBound
                            nWidth = BarsArray(i).Width
                            If BarsArray(i).Position = pbBarFloating And nWidth > nSelectedWidth Then
                                Set GetUndockedBarForTargetWidth = BarsArray(i)
                                nSelectedWidth = nWidth
                            End If
                        Next i
                       
                    End Function

                     

                    Public Sub ClearArray(ByRef BarsArray() As PBCommandBar)
                        Dim nUBound As Long
                        Dim i As Integer
                        nUBound = UBound(BarsArray)
                       
                        For i = 0 To nUBound
                            Set BarsArray(i) = Nothing
                        Next i
                       
                    End Sub

                     

                    Public Function IsMenuBar(cbBar As PBCommandBar) As Boolean
                        'Menu bars are of type builtin and their names end in "Menu Bar"

                        If cbBar.BuiltIn And InStr(cbBar.Name, "Menu Bar") > 0 Then
                            IsMenuBar = True
                            Exit Function
                        End If
                       
                        IsMenuBar = False

                    End Function

                    Public Sub AddBar(cbBar As PBCommandBar, BarsArray() As PBCommandBar)

                        'Redim the array to be one greater than its current size and add the bar to it
                        Dim nUBound As Long
                        nUBound = UBound(BarsArray)
                        nUBound = nUBound + 1
                        ReDim Preserve BarsArray(-1 To nUBound)
                       
                        Set BarsArray(nUBound) = cbBar

                    End Sub

                     

                • Re: ProcessBook Toolbar Organizations
                  mweiss

                  Arash, did any of the information in the replies help you? I think what was posted had the information you need, but I can provide some more info if needed.