Sign in to follow this  
Followers 0
JackDinn

_GUICtrlStatusBar_SetParts

8 posts in this topic

My problem is that im trying to resize the parts of a status bar to fit the text they contain.

the func _GUICtrlStatusBar_SetParts ($hWnd[, $iaParts = -1[, $iaPartWidth = 25]])has the argument partwidth but i dont see how it works ? iv tried playing with it but it looks like it just sets the parts right side pos not the width ?

also _GUICtrlStatusBar_GetTextLength() will return the number of characters but i would need the pixel width to use it & i really dont want to go into using GDI+ if i dont have to.

Cheers all.


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites



JackDinn,

You need to set up an array with the required sizes to use as the $vPartEdge parameter: ;)

Global $aStatus_Parts[4] = [46, 91, 136, -1]
Global $hStatus_Bar = _GUICtrlStatusBar_Create($hMain_Win, $aStatus_Parts)

This was taken directly from one of my scripts and gives me 4 parts in the staus bar of 46 pixels, 45 pixels, 45 pixels, and the rest of the gui width wide. :unsure:

As to the length of the text, my StringSize UDF (look in the sig below) will tell you how many pixels you need for a string in any font/size so you could use that to set the parts to the maximum your possible texts might need (that is how I sized my statusbar in the code above). :D

Give it a try and come back if you have problems. :>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ok thx for the udf to get the pixel width of text, that is certainly helpful :unsure:

Im quite happy with using the status bar by setting the right-hand edges, and if thats what i have to use then so be it, but that does leave me wondering what the "part width" argument is for ? i dont see how the two arguments can work together as they contradict each other , or am i just not understanding what they mean by "part width".

Anyhow i shall continue by using the right hand edge and your udf , should be fine.

thx.


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

JackDinn,

When you use _GUICtrlStatusBar_SetParts you can do one of 2 things:

- 1. As in the example, use the $iaParts array to define the edges of the parts,

- 2. Use an integer variable in the $iaParts parameter to set the number of the parts and then use the $iaPartWidth array to set the widths.

Here is the Help file example reworked to use the second method:

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $iMemo

_Main()

Func _Main()

    Local $hGUI, $hStatus
    Local $iParts = 3                   ; We want 3 parts <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Local $aPartWidth[3] = [75, 75, -1] ; And these are the widths <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ; Create GUI
    $hGUI = GUICreate("StatusBar Set Parts", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create ($hGUI)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Set/Get parts
    ConsoleWrite(_GUICtrlStatusBar_SetParts ($hStatus, $iParts, $aPartWidth) & @CRLF)
    Local $aParts = _GUICtrlStatusBar_GetParts ($hStatus)
    For $iI = 1 To $aParts[0]
        MemoWrite("Part " & $iI & " width .: " & $aParts[$iI])
    Next

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

You can see that the results are the same as the Help file example. :>

So you should now be able to reset your statusbar parts to the size you want. All clear? :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

ahh i see, it was the use of an Int instead of an array for the $iParts variable , i read and read the help file but did not pick up on that fact, i thought they had to be arrays !

many thx for the temp use of your experience :unsure:

On the other part of my op i cant believe how much hassle there is involved in getting a strings pixel width/length :> , I will be able to use for what im wanting but im lucky i was not hoping to get the text pixel length in part of my code that needs to be tightly looped but at an absolute minimum of resources.

All good stuff, thx ;)


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

JackDinn,

how much hassle there is involved in getting a strings pixel width/length

Tell me about it! :>

If you do need it in a tight loop you can always get approximate values fairly quickly by using the average character width - if you ever need it there is a routine in my GUIScrollbars UDF which get that for you. :unsure:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

yea had thought about doing width=(characters * X) and hoping that the differences in each character would balance out.

i mentioned GDI+ above as i was thinking i could maybe use _GDIPlus_GraphicsMeasureString() but on further investigation i find na no such luck, lol.


Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I dunno, tried your example but it still only uses the values as the right hand edge pos !

Looking at my SS you can see its not working

post-38939-0-19971000-1306009671_thumb.j

i had changed your code a little to show 5 parts :-

#include <GuiConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

$Debug_SB = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

Global $iMemo

_Main()

Func _Main()

    Local $hGUI, $hStatus
    Local $iParts = 5               ; We want 5 parts <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Local $aPartWidth[5] = [35, 75,75,75, -1] ; And these are the widths <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

    ; Create GUI
    $hGUI = GUICreate("StatusBar Set Parts", 400, 300)
    $hStatus = _GUICtrlStatusBar_Create ($hGUI)

    ; Create memo control
    $iMemo = GUICtrlCreateEdit("", 2, 2, 396, 274, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

    ; Set/Get parts
    ConsoleWrite(_GUICtrlStatusBar_SetParts ($hStatus, $iParts,$aPartWidth) & @CRLF)
    Local $aParts = _GUICtrlStatusBar_GetParts ($hStatus)
    For $iI = 1 To $aParts[0]
        MemoWrite("Part " & $iI & " width .: " & $aParts[$iI])
    Next

    ; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main

; Write message to memo
Func MemoWrite($sMessage = "")
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

p.s. just found that if i remove the array all together and replace it with an int

_GUICtrlStatusBar_SetParts ($hStatus, $iParts,50)

it works fine, i get 4 equally spaced parts (plus the last) , but as soon as i use the array it reverts to using the right hand edge pos

Edited by JackDinn

Thx all,Jack Dinn.

 

JD's Auto Internet Speed Tester

JD's Clip Catch (With Screen Shot Helper)

Projects :- AutoIt - My projects

My software never has bugs. It just develops random features. :-D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0