I do not know if someone has experienced the same difficulty when there are more than one Item in StatusBar and we wish a new width resizing. And according hmgdoc, Width of items are not assignable.
Normally it will take the first item at most left of StatusBar. But now, this could be changed, with following criteria:
- When just one of cell is Nil Width size.
It will take this cell for trimming. - When all Width sizes are defined.
It will take the bigger width size cell for trimming. - When all Width sizes are equally.
It will take the first cell for trimming, as ever done.
Code: Select all
#include <hmg.ch>
Function Main()
DEFINE WINDOW Form_1 MAIN ;
TITLE "StatusBar ItemWidth resizing demo"
_DefineHotKey ( "Form_1" , 0 , VK_ESCAPE , {|| ThisWindow.Release()} )
DEFINE STATUSBAR FONT "Courier New" SIZE 9
STATUSITEM HMG_PadC("New Project",14) WIDTH 110
STATUSITEM HMG_PadC("Esc for Exit",160) // (Not Width defined)
STATUSITEM HMG_PadC("Version 1.1",14) WIDTH 110
END STATUSBAR
END WINDOW
My_SetStatusBarSize("Form_1",{110,,110})
Form_1.Center
Form_1.Activate
Return Nil
Function My_SetStatusBarSize(cParentForm,anWidths)
Local nParentHandle, nStatusHandle
Local i, nTotWidth := 0
Local nMaxWidth := 0
Local aNil := {}
Local nP := 1
nParentHandle := GetFormHandle ( cParentForm )
i := GetControlIndex ("STATUSBAR",cParentForm)
nStatusHandle := _HMG_SYSDATA [3] [i]
For i := 1 To HMG_LEN (anWidths)
If ValType ( anWidths [i] ) <> 'N'
anWidths [i] := 120
Aadd(aNil,i)
EndIf
If anWidths[i] > nMaxWidth
nMaxWidth := anWidths[i]
nP := i
Endif
nTotWidth := nTotWidth + anWidths [i]
Next i
If HMG_Len(aNil)=1
nP := aNil[1]
ElseIf HMG_Len(aNil)>1
nP := 1
Endif
nTotWidth := nTotWidth - anWidths [nP]
anWidths[nP] := GetWindowWidth ( nParentHandle ) - nTotWidth
InitStatusBarSize ( nStatusHandle, anWidths )
Return Nil
Disable this line in above demo:
// My_SetStatusBarSize("Form_1",{110,,110})
Or you also see when Windows is sizing how StatusBar acts with width size of each StatuBar's item
The main point is, the width size sum of each item in StatusBar should be equal to GetWindowWidth size and when any item is bigger than it can: trimming/re-sizing is required in order to keep same GetWindowWidth size. And for making this, needs to choose one Item. Actually it takes the first item and this some times it is not the ideal result we wish.
This function, will be useful when Window is being resized (maximize or sizing).
Hope you enjoy !