Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > ActiveX COM > Command Bars
  New Posts New Posts RSS Feed - Dynamic Resizing of StatusBar Panes
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dynamic Resizing of StatusBar Panes

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


Joined: 29 October 2008
Location: Australia
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote stefanadelbert Quote  Post ReplyReply Direct Link To This Post Topic: Dynamic Resizing of StatusBar Panes
    Posted: 02 August 2009 at 11:38pm
I'm trying to get the dynamic sizing of the panes in the StatusBar right, but I'm having trouble making it behave how I would like.

I have a left pane, spacer pane (style set to SBPS_STRETCH, also used for some progress messages) and four panes to the right of that. The left-most and four right-most panes should resize to fit their contents. The space pane should take up the remaining space.

This works fine until I put text into the spacer pane that is longer than the width of the pane allows. The panes to the right of the spacer pane appear to get shifted out of the way off to the right.

Is there a way to get the spacer pane (style set to SBPS_STRETCH) to truncate its text so that the right-most panes are still visible?

Thanks
Stefan
Back to Top
stefanadelbert View Drop Down
Groupie
Groupie


Joined: 29 October 2008
Location: Australia
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote stefanadelbert Quote  Post ReplyReply Direct Link To This Post Posted: 03 August 2009 at 8:57pm
I'm trying some workaround code here to truncate the string being displayed in the stretched pane. In order to get this working, I need to know the width of the stretched pane. But if I call StatusBarPane.Width, I get very numbers back that are too small.

If StatusBarPane.Style is set = SBPS_STRETCH, can I rely on StatusBarPane.Width?

Windows XP SP3
VB6
Codejock Suite 13
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 03 August 2009 at 9:22pm
Are they too small in Pixels? What I mean is, if your form is using twips, the StatusBarPane might be returning Pixels which would make it seem to small (not sure, but a lot of CJ controls seem to work in pixels exclusively instead of the parent scalemode). Does Width*Screen.TwipsPerPixelX yield the correct result?
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
stefanadelbert View Drop Down
Groupie
Groupie


Joined: 29 October 2008
Location: Australia
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote stefanadelbert Quote  Post ReplyReply Direct Link To This Post Posted: 03 August 2009 at 9:43pm
I am converting to twips using Screen.TwipsPerPixelX already, so that isn't the problem in this case.

Seems that the StatusBarPane.Width is the width required to display the contents of the Pane if StatusBarPane.Style=SBPS_STRETCH. I need to know the width available so that I can truncate the text as required so that the other panes are not moved around.

Any ideas?
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 04 August 2009 at 10:46am
Sorry for the delay, I had to make up a sample.

You're right that there doesn't seem to be a way to get the StatusPane visible width when the Style is set to SBPS_STRETCH. The Width property just seems to hold the width required to show the text.  Unfortunately, the Handle property always seems to return 0 (I was hoping it might be an Hwnd), so we can't use any APIs on it either.

I got close by looping through the panes and adding all of the widths not including the stretched pane width, then subtracting that from the window width, but the gripper throws that calculation off. You could do a really ugly hack by hard-coding the gripper width, but then might have problems with different skins. In any case, that approach would be a second last resort.

Another even uglier option might be to use the HitTest method of the StatusBar object in a loop and then test when you first hit the pane, and then when you last hit the pane and subtract those values to get the width. This approach would be the last resort I think.

The best option would be to ask CJ if they can expose the actual width for a stretched pane, or perhaps offer a GetRect method for the StatusBarPane object.
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 04 August 2009 at 11:34am
If you are desperate for a solution, this seems to work:


Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long

Private Type Rect
   Left As Long
   Top As Long
   Right As Long
   Bottom As Long
End Type

Private Function GetPaneWidthPx(ByVal po_StatusBarPane As StatusBarPane) As Long
   Dim i As Long
   Dim lo_Pane As StatusBarPane
   Dim l_FoundPane As Boolean
   Dim l_FoundL As Long
   Dim l_FoundR As Long
   Dim lt_Rect As RECT
   Dim l_TestY As Long
  
   GetPaneWidthPx = -1  ' Default to not found value
  
   ' Find the vertical middle of the status bar pane for hit testing
   GetWindowRect Me.CommandBars1.StatusBar.hwnd, lt_Rect
   l_TestY = (lt_Rect.Bottom - lt_Rect.Top) \ 2

   ' Loop through from left > right to test stretched pane boundaries
   For i = 0 To Me.ScaleWidth \ Screen.TwipsPerPixelX
      Set lo_Pane = Me.CommandBars1.StatusBar.HitTest(i, l_TestY)
      If Not lo_Pane Is Nothing Then
         ' We have found a pane at the X,Y position
         If lo_Pane.Id = po_StatusBarPane.Id Then
            ' It is our stretched pane
            If Not l_FoundPane Then
               ' This is the first time we have hit the desired pane
               ' So this is the left boundary
               l_FoundPane = True
               l_FoundL = i
            End If
         Else
            ' We are not over the pane we are testing for
            If l_FoundPane Then
               ' Since we have already found the pane we are looking for,
               ' this marks the right boundary
               l_FoundR = i - 1
               Exit For ' Short-circuit
            End If
         End If
      End If
   Next i
  
   If l_FoundPane Then
      ' We found the pane
      If l_FoundR = 0 Then
         ' We don't have a right boundary saved, so assume the last calculate X index
         l_FoundR = i - 1
      End If
     
      GetPaneWidthPx = l_FoundR - l_FoundL
   End If
End Function

Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
stefanadelbert View Drop Down
Groupie
Groupie


Joined: 29 October 2008
Location: Australia
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote stefanadelbert Quote  Post ReplyReply Direct Link To This Post Posted: 05 August 2009 at 12:29am
Thanks for the help, jpbro. I really appreciate the effort. Both of those workarounds are unfortunately clunky, but would both do the trick. I might go for the 2nd option of calculating the width of the StatusBar and subtracting widths of non-stretched panels.

The available width of a stretched panel should be exposed, but even better would be to have an option to automatically truncate panel contents that overrun the available space (if they are text, of course).
Back to Top
jpbro View Drop Down
Senior Member
Senior Member
Avatar

Joined: 12 January 2007
Status: Offline
Points: 1354
Post Options Post Options   Thanks (0) Thanks(0)   Quote jpbro Quote  Post ReplyReply Direct Link To This Post Posted: 05 August 2009 at 12:41am
Glad to help, and I think that I just found a better solution. After creating your stretched pane, you can set the margins and padding for that pane:


               .SetMargins 0, 0, -100, 0
               .SetPadding 0, 0, 100, 0


The negative margin lets the panes to the right remain visible, and then the positive padding ensures that the stretch text gets chopped so there is no overlapping text. You can adjust the -100/100 pixels as required to fit your other panes.
Product: Xtreme SuitePro (ActiveX) version 16.2.6
Platform: Windows XP - SP3

Language: Visual Basic 6.0 SP6

Back to Top
stefanadelbert View Drop Down
Groupie
Groupie


Joined: 29 October 2008
Location: Australia
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote stefanadelbert Quote  Post ReplyReply Direct Link To This Post Posted: 05 August 2009 at 1:37am
I think I might just use that temporarily. Unfortunately the panes on the left and right are not exactly static. Their contents do change and they should adjust to fit their contents. So I might need to adjust the stretched pane margins dynamically, every time the StatusBar is resized.

Once again, thank you for your help.

Stefan
Back to Top
stefanadelbert View Drop Down
Groupie
Groupie


Joined: 29 October 2008
Location: Australia
Status: Offline
Points: 31
Post Options Post Options   Thanks (0) Thanks(0)   Quote stefanadelbert Quote  Post ReplyReply Direct Link To This Post Posted: 17 August 2009 at 9:48pm
The workaround I used for this was to put a custom control, VB.TextBox, in the statusbar by assigning StatusBarPane.Handle to the hWnd of the FlatEdit.
  • I had to manually tweak the Margins (Top=3) of the StatusBarPane to line up the text with other text in the StatusBar.
  • I set the backcolour to the special colour XPCOLOR_TOOLBAR_FACE using CommandBars.GetSpecialColour(XPCOLOR_TOOLBAR_FACE)
  • I set the font to the font of the StatusBar using CommandBars.StatusBar.Font...
The resizing took car of itself as the StatusBarPane auto sizes (stretches) and as a result automatically sizes the TextBox. The TextBox.Text is automatically truncated.

Thanks to jpbro for his effort on this one.

Stef
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.156 seconds.