Moderators Popular Post Melba23 Posted May 5, 2010 Moderators Popular Post Share Posted May 5, 2010 (edited) BugFix version - 27 Dec 23 Fixed: No default value set for the MaxWidth parameter - took 12 years for someone to notice it! New UDF and new examples below and in zip. I just realised that although I have posted versions of this UDF many times in Help topics, I had never actually posted a "final" version here in Example scripts - better late than never, I suppose! StringSize takes a text string and calculates the size of label required to hold it as well as formatting the string to fit. Now AutoIt will, of course, size a label automatically to fit a text string, but it will not format the string in any way - what you use as the string is what you get in the label. If you do set any label sizes the text will be wrapped, but you can only determine the correct size of the label by trial and error. StringSize will, however, reformat the string to fit in a given width and tell you the required height so that you can read it all - whatever the font type or size - and you do not have to do the formatting beforehand. Here is a simple example to show what I mean (you need the UDF in the same folder for all the examples): Spoiler #include <GUIConstantsEx.au3> #include "StringSize.au3" $sText = " I am a very long line and I am not formatted in any way so that I will not fit within the width of the GUI that surrounds me!" $hGUI = GUICreate("Test", 500, 500) ; A label with no width or height set GUICtrlCreateLabel($sText, 10, 10) GUICtrlSetBkColor(-1, 0xFF8080) ; A label with no height set GUICtrlCreateLabel($sText, 10, 50, 200) GUICtrlSetBkColor(-1, 0xC0C0FF) ; A label sized by StringSize $aSize = _StringSize($sText, Default, Default, Default, "", 200) GUICtrlCreateLabel($aSize[0], 10, 90, $aSize[2], $aSize[3]) GUICtrlSetBkColor(-1, 0x80FF80) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd And here is an example showing how StringSize can deal with different fonts and text sizes: Spoiler expandcollapse popup#include <GUIConstantsEx.au3> #include "StringSize.au3" Global $aFont[4] = ["Arial", "Tahoma", "Courier New", "Comic Sans MS"] Global $aSize[4] = [9, 12, 10, 15] Global $aWeight[4] = [200, 400, 600, 800] Global $aAttrib[4] = [0, 2, 4, 0] Global $aMaxWidth[4] = [250, 300, 400, 500] Global $aColour[4] = [0xFFFF88, 0xBBFF88, 0xBB88FF, 0xFF88FF] Global $aButMsg[4] = ["Press for next example", "Click here", "Please push", "And the next one please..."] $sLabelMsg = "This is a message with very long lines which are unlikely to fit within a GUI of a specified maximum width. " & _ "This UDF will return the size of rectangle needed to display the message in a selected font and size." & @CRLF & @CRLF & _ "The GUI can then be sized to fit and accurately placed on screen. Other controls, such as the automatically " & _ "sized button under this label, can also be accurately positioned relative to the text." $hGUI = GUICreate("String Sizing Test", 500, 500) $hLabel = GUICtrlCreateLabel("", 10, 10, -1, -1, 1) $hNext = GUICtrlCreateButton("", 210, 460, 80, 30) GUISetState(@SW_HIDE) While 1 $sFont = $aFont[Random(0, 3, 1)] $iSize = $aSize[Random(0, 3, 1)] $iWeight = $aWeight[Random(0, 3, 1)] $iAttrib = $aAttrib[Random(0, 3, 1)] $iMaxWidth = Random(200, 850, 1) $iColour = $aColour[Random(0, 3, 1)] $sButMsg = $aButMsg[Random(0, 3, 1)] $aButReturn = _StringSize($sButMsg) $aMsgReturn = _StringSize($sLabelMsg, $iSize, $iWeight, $iAttrib, $sFont, $iMaxWidth) $iError = @error If IsArray($aMsgReturn) = 1 Then WinMove("String Sizing Test", "", (@DesktopWidth - ($aMsgReturn[2] + 25)) / 2, (@DesktopHeight - ($aMsgReturn[3] + 85)) / 2, $aMsgReturn[2] + 25, $aMsgReturn[3] + 85 ) GUISetState(@SW_SHOW, $hGUI) ControlMove($hGUI, "", $hLabel, 10, 10, $aMsgReturn[2], $aMsgReturn[3]) GUICtrlSetData($hLabel, $aMsgReturn[0]) GUICtrlSetFont($hLabel, $iSize, $iWeight, $iAttrib, $sFont) GUICtrlSetBkColor($hLabel, $iColour) ControlMove($hGUI, "", $hNext, ($aMsgReturn[2] - $aButReturn[2]) / 2, $aMsgReturn[3] + 20, $aButReturn[2] + 20, 30) GUICtrlSetData($hNext, $aButReturn[0]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hNext ExitLoop EndSwitch WEnd Else MsgBox(0, "Error", "Code = " & $iError) EndIf WEnd You can see that the GUI is perfectly sized each time and that the button is always the right size and in the right place. StringSize returns an array which contains the formatted text to display and the size of the label needed to display it. All you need to do is to use the array elements when you create your label. Try changing the values in $aFont and $aSize if you want to try you own favourites - but beware, StringSize will return an error if you make the size so large that it cannot fit a word into the label width. NEW A more complex example showing how formatted and unformatted text can be sized correctly. The width of GUI holding the unformatted text varies randomly in width (the current value is displayed at top right): Spoiler expandcollapse popup; SizeString Test New ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include <GUIConstantsEx.au3> #Include <GuiStatusBar.au3> #include "StringSize.au3" ; Declare arrays to hold parameters Global $aFont[4] = ["Arial", "Tahoma", "Courier New", "Comic Sans MS"] Global $aSize[4] = [9, 12, 10, 15] Global $aWeight[4] = [200, 400, 600, 800] Global $aAttrib[4] = [0, 2, 4, 0] Global $aMaxWidth[4] = [250, 300, 400, 500] Global $aColour[4] = [0xFFFFD0, 0xD0FFD0, 0xD0D0FF, 0xFFD0FF] Global $aButMsg[4] = ["Press for next example", "Click here", "Please push", "And the next one please..."] ; Declare preformatted and unformatted strings $FormatMsg = _ "This is a pre-formatted message with lines of pre-set " & @CRLF & _ "lengths which will not be wrapped. The UDF will " & @CRLF & _ "return the size of rectangle needed to display it " & @CRLF & _ "in a selected font and size." & @CRLF & @CRLF & _ "The GUI can then be sized to fit and accurately placed " & @CRLF & _ "on screen. Other controls, such as the automatically " & @CRLF & _ "sized button under this label, can also be accurately " & @CRLF & _ "positioned relative to the text." $UnformatMsg = _ "This is an unformatted message with 2 very long lines which are unlikely to fit within the maximum width specified. The UDF will return the size of rectangle needed to display it in a selected font and size." & @CRLF & @CRLF & _ "The GUI can then be sized to fit and accurately placed on screen. Other controls, such as the automatically sized button under this label, can also be accurately positioned relative to the text." ; Create GUI $hGUI = GUICreate("SizeString Test", 500, 500) ; Create radios to select mode of UDF GUIStartGroup() $hRadio_Pre = GUICtrlCreateRadio(" Preformatted", 10, 5, 85, 20) GUICtrlSetState(-1, $GUI_CHECKED) GUICtrlSetResizing(-1, $GUI_DOCKALL) $hRadio_Un = GUICtrlCreateRadio(" Unformatted", 95, 5, 85, 20) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUIStartGroup() $hWidth_Label = GUICtrlCreateLabel("W:900", 460, 8, 40, 20) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT + $GUI_DOCKWIDTH) ; Create and hide status bar Local $aStatus_Parts[4] = [20, 50, 120, -1] Global $hStatus_Bar = _GUICtrlStatusBar_Create($hGUI, $aStatus_Parts) Global $iStatus_Depth = _GUICtrlStatusBar_GetHeight($hStatus_Bar) + 5 _GUICtrlStatusBar_ShowHide($hStatus_Bar, @SW_SHOW) GUISetState() While 1 ; Choose parameter values $sFont = $aFont[Random(0, 3, 1)] $iSize = $aSize[Random(0, 3, 1)] $iWeight = $aWeight[Random(0, 3, 1)] $iAttrib = $aAttrib[Random(0, 3, 1)] $iMaxWidth = 10 * Random(20, 85, 1) $iColour = $aColour[Random(0, 3, 1)] $sButMsg = $aButMsg[Random(0, 3, 1)] ; Run UDF, $aButReturn = _StringSize($sButMsg) If GUICtrlRead($hRadio_Pre) = 1 Then $aMsgReturn = _StringSize($FormatMsg, $iSize, $iWeight, $iAttrib, $sFont) Else $aMsgReturn = _StringSize($UnformatMsg, $iSize, $iWeight, $iAttrib, $sFont, $iMaxWidth) EndIf $iError = @error ; If no error If IsArray($aMsgReturn) = 1 Then ; Size GUI as required WinMove($hGUI, "", (@DesktopWidth - ($aMsgReturn[2] + 25)) / 2, (@DesktopHeight - ($aMsgReturn[3] + 105)) / 2, $aMsgReturn[2] + 25, $aMsgReturn[3] + 105 + $iStatus_Depth) ; Resize and fill status bar _GUICtrlStatusBar_Resize ($hStatus_Bar) _GUICtrlStatusBar_SetText($hStatus_Bar, $iSize, 0) _GUICtrlStatusBar_SetText($hStatus_Bar, $iWeight, 1) $sAttrib = "Normal" Switch $iAttrib Case 2 $sAttrib = "Italic" Case 4 $sAttrib = "Underline" EndSwitch _GUICtrlStatusBar_SetText($hStatus_Bar, $sAttrib, 2) _GUICtrlStatusBar_SetText($hStatus_Bar, $sFont, 3) If GUICtrlRead($hRadio_Un) = 1 Then GUICtrlSetData($hWidth_Label, "W:" & $iMaxWidth); _GUICtrlStatusBar_SetText($hStatus_Bar, $iMaxWidth & " wide", 4) Else GUICtrlSetData($hWidth_Label, "");_GUICtrlStatusBar_SetText($hStatus_Bar, "", 4) EndIf ; Create correctly sized label to fit text $hLabel = GUICtrlCreateLabel($aMsgReturn[0], 10, 30, $aMsgReturn[2], $aMsgReturn[3], 1) GUICtrlSetFont(-1, $iSize, $iWeight, $iAttrib, $sFont) GUICtrlSetBkColor(-1, $iColour) ; Create correctly sized and positioned button $hNext = GUICtrlCreateButton($sButMsg, ($aMsgReturn[2] - $aButReturn[2]) / 2, $aMsgReturn[3] + 40, $aButReturn[2] + 20, 30) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hNext, $hRadio_Pre, $hRadio_Un ExitLoop EndSwitch WEnd ; Delete label and button GUICtrlDelete($hNext) GUICtrlDelete($hLabel) Else MsgBox(0, "Error", "Code = " & $iError) EndIf WEnd NEW And a final example showing how you can get your text in the largest possible font to fit in a given space: Spoiler expandcollapse popup#include <GUIConstantsEx.au3> #include "StringSize.au3" ; Declare arrays to hold parameters Global $aFont[4] = ["Arial", "Tahoma", "Courier New", "Comic Sans MS"] Global $aWeight[4] = [200, 400, 600, 800] Global $aAttrib[4] = [0, 2, 4, 0] Global $aColour[4] = [0xFFFFD0, 0xD0FFD0, 0xD0D0FF, 0xFFD0FF] $sText = "The UDF will calculate the largest possible font size which will allow this text to fit in the randomly sized label. " & _ "Pressing the 'Increase' button will use the next size up so you can see how successful it was. " & @CRLF & _ "Note that the UDF is pessimistic and will leave small borders to the right and at the bottom of the text, so you might " & _ "be able to go one size up in a few cases, although this risks clipping the trailing edges of italic letters or the tails of letters such as 'g'." $hGUI = GUICreate("Test", 500, 500, 100, 100) $hButton_Next = GUICtrlCreateButton("Next", 10, 10, 80, 30) GUICtrlSetResizing(-1, $GUI_DOCKALL) $hLabel_Size = GUICtrlCreateLabel("", 100, 10, 40, 30) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUICtrlSetFont(-1, 24) $hButton_Increase = GUICtrlCreateButton("Increase", 150, 10, 80, 30) GUICtrlSetResizing(-1, $GUI_DOCKALL) GUISetState() While 1 ; Choose parameter values $iX = 10 * Random(25, 50, 1) $iY = 10 * Random(10, 40, 1) $sFont = $aFont[Random(0, 3, 1)] $iWeight = $aWeight[Random(0, 3, 1)] $iAttrib = $aAttrib[Random(0, 3, 1)] $iColour = $aColour[Random(0, 3, 1)] WinMove($hGUI, "", 100, 100, $iX + 26, $iY + 85) $hLabel = GUICtrlCreateLabel("", 10, 50, $iX, $iY) GUICtrlSetBkColor(-1, $iColour) For $iSize = 5 To 50 $aSize = _StringSize($sText, $iSize, $iWeight, $iAttrib, $sFont, $iX) If $aSize[3] > $iY Then $iSize -= 1 ExitLoop EndIf Next GUICtrlSetData($hLabel_Size, $iSize) GUICtrlSetFont($hLabel, $iSize, $iWeight, $iAttrib, $sFont) $aSize = _StringSize($sText, $iSize, $iWeight, $iAttrib, $sFont, $iX) GUICtrlSetData($hLabel, $aSize[0]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_Next GUICtrlDelete($hLabel) GUICtrlSetData($hLabel_Size, "") ExitLoop Case $hButton_Increase GUICtrlSetData($hLabel, "") $iSize += 1 GUICtrlSetData($hLabel_Size, $iSize) GUICtrlSetFont($hLabel, $iSize, $iWeight, $iAttrib, $sFont) $aSize = _StringSize($sText, $iSize, $iWeight, $iAttrib, $sFont, $iX) GUICtrlSetData($hLabel, $aSize[0]) EndSwitch WEnd WEnd Finally here is the UDF itself: Spoiler expandcollapse popup#include-once ; #INDEX# ============================================================================================================ ; Title .........: _StringSize ; AutoIt Version : v3.2.12.1 or higher ; Language ......: English ; Description ...: Returns size of rectangle required to display string - maximum width can be chosen ; Remarks .......: ; Note ..........: ; Author(s) .....: Melba23 - thanks to trancexx for the default DC code ; ==================================================================================================================== ;#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #CURRENT# ========================================================================================================== ; _StringSize: Returns size of rectangle required to display string - maximum width can be chosen ; ==================================================================================================================== ; #INTERNAL_USE_ONLY#================================================================================================= ; _StringSize_Error_Close: Releases DC and deletes font object after error ; _StringSize_DefaultFontName: Determines Windows default font ; ==================================================================================================================== ; #FUNCTION# ========================================================================================================= ; Name...........: _StringSize ; Description ...: Returns size of rectangle required to display string - maximum permitted width can be chosen ; Syntax ........: _StringSize($sText[, $iSize[, $iWeight[, $iAttrib[, $sName[, $iWidth[, $hWnd]]]]]]) ; Parameters ....: $sText - String to display ; $iSize - [optional] Font size in points - (default = 8.5) ; $iWeight - [optional] Font weight - (default = 400 = normal) ; $iAttrib - [optional] Font attribute (0-Normal (default), 2-Italic, 4-Underline, 8 Strike) ; + 1 if tabs are to be expanded before sizing ; $sName - [optional] Font name - (default = Tahoma) ; $iWidth - [optional] Max width for rectangle - (default = 0 => width of original string) ; $hWnd - [optional] GUI in which string will be displayed - (default 0 => normally not required) ; Requirement(s) : v3.2.12.1 or higher ; Return values .: Success - Returns 4-element array: ($iWidth set // $iWidth not set) ; |$array[0] = String reformatted with additonal @CRLF // Original string ; |$array[1] = Height of single line in selected font // idem ; |$array[2] = Width of rectangle required for reformatted // original string ; |$array[3] = Height of rectangle required for reformatted // original string ; Failure - Returns 0 and sets @error: ; |1 - Incorrect parameter type (@extended = parameter index) ; |2 - DLL call error - extended set as follows: ; |1 - GetDC failure ; |2 - SendMessage failure ; |3 - GetDeviceCaps failure ; |4 - CreateFont failure ; |5 - SelectObject failure ; |6 - GetTextExtentPoint32 failure ; |3 - Font too large for chosen max width - a word will not fit ; Author ........: Melba23 - thanks to trancexx for the default DC code ; Modified ......: ; Remarks .......: The use of the $hWnd parameter is not normally necessary - it is only required if the UDF does not ; return correct dimensions without it. ; Related .......: ; Link ..........: ; Example .......: Yes ;===================================================================================================================== Func _StringSize($sText, $iSize = 8.5, $iWeight = 400, $iAttrib = 0, $sName = "", $iMaxWidth = 0, $hWnd = 0) ; Set parameters passed as Default If $iSize = Default Then $iSize = 8.5 If $iWeight = Default Then $iWeight = 400 If $iAttrib = Default Then $iAttrib = 0 If $sName = "" Or $sName = Default Then $sName = _StringSize_DefaultFontName() If $iMaxWidth = Default Then $iMaxWidth = 0 ; Check parameters are correct type If Not IsString($sText) Then Return SetError(1, 1, 0) If Not IsNumber($iSize) Then Return SetError(1, 2, 0) If Not IsInt($iWeight) Then Return SetError(1, 3, 0) If Not IsInt($iAttrib) Then Return SetError(1, 4, 0) If Not IsString($sName) Then Return SetError(1, 5, 0) If Not IsNumber($iMaxWidth) Then Return SetError(1, 6, 0) If Not IsHwnd($hWnd) And $hWnd <> 0 Then Return SetError(1, 7, 0) Local $aRet, $hDC, $hFont, $hLabel = 0, $hLabel_Handle ; Check for tab expansion flag Local $iExpTab = BitAnd($iAttrib, 1) ; Remove possible tab expansion flag from font attribute value $iAttrib = BitAnd($iAttrib, BitNot(1)) ; If GUI handle was passed If IsHWnd($hWnd) Then ; Create label outside GUI borders $hLabel = GUICtrlCreateLabel("", -10, -10, 10, 10) $hLabel_Handle = GUICtrlGetHandle(-1) GUICtrlSetFont(-1, $iSize, $iWeight, $iAttrib, $sName) ; Create DC $aRet = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hLabel_Handle) If @error Or $aRet[0] = 0 Then GUICtrlDelete($hLabel) Return SetError(2, 1, 0) EndIf $hDC = $aRet[0] $aRet = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hLabel_Handle, "int", 0x0031, "wparam", 0, "lparam", 0) ; $WM_GetFont If @error Or $aRet[0] = 0 Then GUICtrlDelete($hLabel) Return SetError(2, _StringSize_Error_Close(2, $hDC), 0) EndIf $hFont = $aRet[0] Else ; Get default DC $aRet = DllCall("user32.dll", "handle", "GetDC", "hwnd", $hWnd) If @error Or $aRet[0] = 0 Then Return SetError(2, 1, 0) $hDC = $aRet[0] ; Create required font $aRet = DllCall("gdi32.dll", "int", "GetDeviceCaps", "handle", $hDC, "int", 90) ; $LOGPIXELSY If @error Or $aRet[0] = 0 Then Return SetError(2, _StringSize_Error_Close(3, $hDC), 0) Local $iInfo = $aRet[0] $aRet = DllCall("gdi32.dll", "handle", "CreateFontW", "int", -$iInfo * $iSize / 72, "int", 0, "int", 0, "int", 0, _ "int", $iWeight, "dword", BitAND($iAttrib, 2), "dword", BitAND($iAttrib, 4), "dword", BitAND($iAttrib, 8), "dword", 0, "dword", 0, _ "dword", 0, "dword", 5, "dword", 0, "wstr", $sName) If @error Or $aRet[0] = 0 Then Return SetError(2, _StringSize_Error_Close(4, $hDC), 0) $hFont = $aRet[0] EndIf ; Select font and store previous font $aRet = DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hDC, "handle", $hFont) If @error Or $aRet[0] = 0 Then Return SetError(2, _StringSize_Error_Close(5, $hDC, $hFont, $hLabel), 0) Local $hPrevFont = $aRet[0] ; Declare variables Local $avSize_Info[4], $iLine_Length, $iLine_Height = 0, $iLine_Count = 0, $iLine_Width = 0, $iWrap_Count, $iLast_Word, $sTest_Line ; Declare and fill Size structure Local $tSize = DllStructCreate("int X;int Y") DllStructSetData($tSize, "X", 0) DllStructSetData($tSize, "Y", 0) ; Ensure EoL is @CRLF and break text into lines $sText = StringRegExpReplace($sText, "((?<!\x0d)\x0a|\x0d(?!\x0a))", @CRLF) Local $asLines = StringSplit($sText, @CRLF, 1) ; For each line For $i = 1 To $asLines[0] ; Expand tabs if required If $iExpTab Then $asLines[$i] = StringReplace($asLines[$i], @TAB, " XXXXXXXX") EndIf ; Size line $iLine_Length = StringLen($asLines[$i]) DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $asLines[$i], "int", $iLine_Length, "ptr", DllStructGetPtr($tSize)) If @error Then Return SetError(2, _StringSize_Error_Close(6, $hDC, $hFont, $hLabel), 0) If DllStructGetData($tSize, "X") > $iLine_Width Then $iLine_Width = DllStructGetData($tSize, "X") If DllStructGetData($tSize, "Y") > $iLine_Height Then $iLine_Height = DllStructGetData($tSize, "Y") Next ; Check if $iMaxWidth has been both set and exceeded If $iMaxWidth <> 0 And $iLine_Width > $iMaxWidth Then ; Wrapping required ; For each Line For $j = 1 To $asLines[0] ; Size line unwrapped $iLine_Length = StringLen($asLines[$j]) DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $asLines[$j], "int", $iLine_Length, "ptr", DllStructGetPtr($tSize)) If @error Then Return SetError(2, _StringSize_Error_Close(6, $hDC, $hFont, $hLabel), 0) ; Check wrap status If DllStructGetData($tSize, "X") < $iMaxWidth - 4 Then ; No wrap needed so count line and store $iLine_Count += 1 $avSize_Info[0] &= $asLines[$j] & @CRLF Else ; Wrap needed so zero counter for wrapped lines $iWrap_Count = 0 ; Build line to max width While 1 ; Zero line width $iLine_Width = 0 ; Initialise pointer for end of word $iLast_Word = 0 ; Add characters until EOL or maximum width reached For $i = 1 To StringLen($asLines[$j]) ; Is this just past a word ending? If StringMid($asLines[$j], $i, 1) = " " Then $iLast_Word = $i - 1 ; Increase line by one character $sTest_Line = StringMid($asLines[$j], 1, $i) ; Get line length $iLine_Length = StringLen($sTest_Line) DllCall("gdi32.dll", "bool", "GetTextExtentPoint32W", "handle", $hDC, "wstr", $sTest_Line, "int", $iLine_Length, "ptr", DllStructGetPtr($tSize)) If @error Then Return SetError(2, _StringSize_Error_Close(6, $hDC, $hFont, $hLabel), 0) $iLine_Width = DllStructGetData($tSize, "X") ; If too long exit the loop If $iLine_Width >= $iMaxWidth - 4 Then ExitLoop Next ; End of the line of text? If $i > StringLen($asLines[$j]) Then ; Yes, so add final line to count $iWrap_Count += 1 ; Store line $avSize_Info[0] &= $sTest_Line & @CRLF ExitLoop Else ; No, but add line just completed to count $iWrap_Count += 1 ; Check at least 1 word completed or return error If $iLast_Word = 0 Then Return SetError(3, _StringSize_Error_Close(0, $hDC, $hFont, $hLabel), 0) ; Store line up to end of last word $avSize_Info[0] &= StringLeft($sTest_Line, $iLast_Word) & @CRLF ; Strip string to point reached $asLines[$j] = StringTrimLeft($asLines[$j], $iLast_Word) ; Trim leading whitespace $asLines[$j] = StringStripWS($asLines[$j], 1) ; Repeat with remaining characters in line EndIf WEnd ; Add the number of wrapped lines to the count $iLine_Count += $iWrap_Count EndIf Next ; Reset any tab expansions If $iExpTab Then $avSize_Info[0] = StringRegExpReplace($avSize_Info[0], "\x20?XXXXXXXX", @TAB) EndIf ; Complete return array $avSize_Info[1] = $iLine_Height $avSize_Info[2] = $iMaxWidth ; Convert lines to pixels and add drop margin $avSize_Info[3] = ($iLine_Count * $iLine_Height) + 4 Else ; No wrapping required ; Create return array (add drop margin to height) Local $avSize_Info[4] = [$sText, $iLine_Height, $iLine_Width, ($asLines[0] * $iLine_Height) + 4] EndIf ; Clear up DllCall("gdi32.dll", "handle", "SelectObject", "handle", $hDC, "handle", $hPrevFont) DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hFont) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "handle", $hDC) If $hLabel Then GUICtrlDelete($hLabel) Return $avSize_Info EndFunc ;==>_StringSize ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _StringSize_Error_Close ; Description ...: Releases DC and deleted font object if required after error ; Syntax ........: _StringSize_Error_Close ($iExtCode, $hDC, $hGUI) ; Parameters ....: $iExtCode - code to return ; $hDC, $hGUI - handles as set in _StringSize function ; Return value ..: $iExtCode as passed ; Author ........: Melba23 ; Modified.......: ; Remarks .......: This function is used internally by _StringSize ; =============================================================================================================================== Func _StringSize_Error_Close($iExtCode, $hDC = 0, $hFont = 0, $hLabel = 0) If $hFont <> 0 Then DllCall("gdi32.dll", "bool", "DeleteObject", "handle", $hFont) If $hDC <> 0 Then DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "handle", $hDC) If $hLabel Then GUICtrlDelete($hLabel) Return $iExtCode EndFunc ;=>_StringSize_Error_Close ; #INTERNAL_USE_ONLY#============================================================================================================ ; Name...........: _StringSize_DefaultFontName ; Description ...: Determines Windows default font ; Syntax ........: _StringSize_DefaultFontName() ; Parameters ....: None ; Return values .: Success - Returns name of system default font ; Failure - Returns "Tahoma" ; Author ........: Melba23, based on some original code by Larrydalooza ; Modified.......: ; Remarks .......: This function is used internally by _StringSize ; =============================================================================================================================== Func _StringSize_DefaultFontName() ; Get default system font data Local $tNONCLIENTMETRICS = DllStructCreate("uint;int;int;int;int;int;byte[60];int;int;byte[60];int;int;byte[60];byte[60];byte[60]") DLLStructSetData($tNONCLIENTMETRICS, 1, DllStructGetSize($tNONCLIENTMETRICS)) DLLCall("user32.dll", "int", "SystemParametersInfo", "int", 41, "int", DllStructGetSize($tNONCLIENTMETRICS), "ptr", DllStructGetPtr($tNONCLIENTMETRICS), "int", 0) Local $tLOGFONT = DllStructCreate("long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]", DLLStructGetPtr($tNONCLIENTMETRICS, 13)) If IsString(DllStructGetData($tLOGFONT, 14)) Then Return DllStructGetData($tLOGFONT, 14) Else Return "Tahoma" EndIf EndFunc ;=>_StringSize_DefaultFontName And all 5 files in zip format: StringSize.zip I hope you find this useful - I certainly do. M23 Edited December 27, 2023 by Melba23 Skitty, ioa747, Xandy and 11 others 11 3 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted May 5, 2010 Share Posted May 5, 2010 Hang on a sec... You release plenty of other UDF's for which this is needed (Toast, Extended MsgBox etc.) and never post this?? Is making a GUI the most effective way of doing this? MeasureString is probably a better way to go. AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 5, 2010 Author Moderators Share Posted May 5, 2010 Mat,You release plenty of other UDF's for which this is needed (Toast, Extended MsgBox etc.) and never post this??Not quite, the UDF was indeed included in the topics of the UDFs you mention - and in many other topics scattered across the Help sections - I just never released it as a standalone UDF in the Examples section. Not sure I understand your second point. Why else do you need to get the size of a chunk of text if not to put it in a GUI? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Kip Posted May 5, 2010 Share Posted May 5, 2010 There are plenty of UDF's like this. Even I made one and posted in Examples. I can't find it for you now, though. MailSpons: Fake SMTP server for safe email testing Dutch postcode & address API. Link to comment Share on other sites More sharing options...
Datenshi Posted May 5, 2010 Share Posted May 5, 2010 (edited) Melba, can this be used to get stringsize in order to resize a "progressOn" window, to fit the strings within it?(currently it has a default size) I'd like a way to resize the ProgressOn window based on the text within it. Too long strings get cut off. Edited May 5, 2010 by Datenshi RapidQueuer 2.4 - For Rapidshare.comOpensubtitles Hashing FuncRevision3 PlayerGTPlayer BetaIMDB & Poster Grabber v1.3Fetgrek.com - My Website Link to comment Share on other sites More sharing options...
James Posted May 5, 2010 Share Posted May 5, 2010 There are plenty of UDF's like this. Even I made one and posted in Examples. I can't find it for you now, though.Here you go. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Mat Posted May 5, 2010 Share Posted May 5, 2010 My point is that always making GUI's is not a particularly glamorous solution. As I have not tried to make the function myself I cannot say if it will be easy to do or not, but making a GUI and then deleting it just to get the size of a label... Sounds more like a workaround to me. An idea I've just had is possibly a new function for sizing an existing label, then returning the size. That would stop the need for extra GUI's, save on speed, and do what this is probably going to be used for anyway. You only need to input an id for a label and a width, and it will do its stuff and return a height. As mentioned, I am not 'in the know' and so all this is complete speculation from looking at your code. AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Author Moderators Share Posted May 6, 2010 (edited) Mat,Sounds more like a workaround to mePlease do try another way - there is room for all of them. Kip,There are plenty of UDF's like this. Even I made one and posted in ExamplesThis is not like your UDF - try it and see! M23Edit: Speeling! Edited May 6, 2010 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Yoriz Posted May 6, 2010 Share Posted May 6, 2010 Cheers, ive been using a version of this already, may be differant in the version you posted but note that i found the need to guiswitch to the gui i was creating when adding controls after using stringsize. Local $HeaderTextSize = _StringSize($sHeaderText, $oSelf.HeaderFontSize, $oSelf.HeaderFontWeight,$oSelf.HeaderFontAttribute, $oSelf.HeaderFontFontName) GUISwitch(HWnd($oSelf.GuiHandle)) $HeaderTextSize[1] += 2 $hCtrl = _oGUICtrlLabel($sHeaderText, $iLeft, $iTop, $HeaderTextSize[2], $HeaderTextSize[1], BitOR($SS_CENTER,$SS_CENTERIMAGE)) GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Author Moderators Share Posted May 6, 2010 Datenshi, Apologies, I missed your post earlier in the noise! can this be used to get stringsize in order to resize a "progressOn" windowOf course, but you need to use WinMove and ControlMove to resize the dialog, labels and progress bar. How you do it depends on whether you want to use a very wide dialog with a single line of text or a block of wrapped text with a normal width dialog (see the examples): expandcollapse popup#include "StringSize.au3" ; The long text we want to fit in the dialog $sText = "I am a very long line and I will not fit within the width of a normal ProgressOn dialog even with a lot of dieting!" ; Wide dialog $aSize = _StringSize($sText, 11, 800, 0, "Segoe UI") ProgressOn("Progress Meter", $sText, "0 percent") WinMove("Progress Meter", "", (@DesktopWidth - ($aSize[2] + 30)) / 2, Default, $aSize[2] + 30) ControlMove("Progress Meter", "", "[CLASS:msctls_progress32; INSTANCE:1]", Default, Default, $aSize[2] - 15) For $i = 10 to 100 step 10 Sleep(1000) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "Complete") Sleep(500) ProgressOff() ; Wrapped text $aSize = _StringSize($sText, 11, 800, 0 , "Segoe UI", 250) ProgressOn("Progress Meter", $aSize[0], "0 percent") WinMove("Progress Meter", "", (@DesktopWidth - ($aSize[2] + 30)) / 2, Default, $aSize[2] + 30, $aSize[3] + 80) ControlMove("Progress Meter", "", "[CLASS:Static; INSTANCE:1]", Default, Default, $aSize[2], $aSize[3]) ControlMove("Progress Meter", "", "[CLASS:msctls_progress32; INSTANCE:1]", Default, $aSize[3] - 5, $aSize[2] - 15) ControlMove("Progress Meter", "", "[CLASS:Static; INSTANCE:2]", Default, $aSize[3] + 20) For $i = 10 to 100 step 10 Sleep(1000) ProgressSet( $i, $i & " percent") Next ProgressSet(100 , "Done", "Complete") Sleep(500) ProgressOff() I had to guess at the caption font, but the values I chose seem to work well - and the values for resizing the dialog and the controls were chosen empirically as well. Why the progress bar needs to be set to a smaller width I have no idea - blame Bill Gates! I hope that is what you wanted. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 6, 2010 Author Moderators Share Posted May 6, 2010 Yoriz,i found the need to guiswitch to the gui i was creating when adding controls after using stringsizeSorry about that. As MAt pointed out, the UDF does create and then destroy a GUI (to get the font object required for sizing) so I imagine this is what is causing the problem.I have only ever used the UDF BEFORE creating the GUI and any of its controls so I had not noticed this before. Let me think for a while about how we might get around it. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Yoriz Posted May 6, 2010 Share Posted May 6, 2010 (edited) Hey no need to appologise, i just got used to swoppping back . would this work ? $hWndPrevious = GUISwitch(WinGetHandle("Program Manager","")) ; at the start of your udf function If $hWndPrevious Then GUISwitch($hWndPrevious) ; just before returning from your udf function There may be a nicer way to get the previous window. Edited May 6, 2010 by Yoriz GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2010 Author Moderators Share Posted May 7, 2010 Yoriz,I do not get the same problem as you when I use StringSize and then try to create more controls in a GUI: #include <GUIConstantsEx.au3> #include "StringSize.au3" $sText = "pppppppppppp ppppp ppppppppp pppppppppp ppppppppppp ppppppp ppppp ppp" ; Create GUI $hGUI = GUICreate("Test", 500, 500) ; Create first control $hButton = GUICtrlCreateButton("Test", 10, 100, 80, 30) ; Run StringSize $aSize = _StringSize($sText, Default, Default, Default, Default, 200) ; Create second control $hLabel = GUICtrlCreateLabel($aSize[0], 10, 10, 200, $aSize[3]) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEndFor me that code runs without problem and both controls appear in the GUI.Your code looks as if you are using AutoItObject - I wonder if that might be causing the problem? I do not know enough about AIO to make any sensible comments about the possibility.M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Yoriz Posted May 7, 2010 Share Posted May 7, 2010 Sorry about the missunderstanding, yes im using oop and its probably not that causing it either, i bet im probably creating guis in a strange way thats causing the problem. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 7, 2010 Author Moderators Share Posted May 7, 2010 Yoriz, Could you post some code that does not work so I could play with it. I already have the AIO UDFs. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
llewxam Posted May 18, 2010 Share Posted May 18, 2010 I am using your code kinda backwards - I know my width maximum (160) and I know my height maximum (55), so I run my string through _StringSize with the font size set too high and decrease by one, and compare $array[3] to 55. If it is less than 55, we're gold, ExitLoop and go. Sometimes it hangs though, here is an example: For $a = 24 To 1 Step -1 $findIt = _StringSize("CAT5E Crossover Coupler CAT5E Crossover Coupler", $a, Default, Default, "Arial", 160) If $findIt[3] <= 55 Then MsgBox(0, "font size to use: " & $a) ExitLoop EndIf Next The above works, but run them together as "CAT5E Crossover CouplerCAT5E Crossover Coupler" and it hangs. Got a solution up your sleeve? Thanks, wonderful UDF as always! Ian My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 20, 2010 Author Moderators Share Posted May 20, 2010 llewxam, Got a solution up your sleeve?Yes, I messed up the error-checking return code - which I had already realised while I was away last week. The UDF should return an error if it cannot fit a word into the minimum width required - which should happen a lot in your case! I messed up the original error return code so you did not get an error returned and the UDF just ran on and on........ I have amended the UDF in the first post to get over this - but you will now need to amend your code to look for the @error returns which you will now get: For $a = 24 To 1 Step -1 ConsoleWrite($a & " - ") $findIt = _StringSize("CAT5E Crossover CouplerCAT5E Crossover Coupler", $a, Default, Default, "Arial", 160) If Not @error Then ConsoleWrite($findIt[3] & @CRLF) If $findIt[3] <= 55 Then MsgBox(0, "", "font size to use: " & $a) ExitLoop EndIf Else ConsoleWrite("error " & @error & @CRLF) EndIf Next The ConsoleWrites are obviously there to show you what is going on - you can delete them when you have seen what is going on: 24 - error 4 23 - error 4 22 - error 4 21 - error 4 20 - error 4 19 - error 4 18 - error 4 17 - 129 16 - 124 15 - 119 14 - 67 13 - 61 12 - 58 11 - 52 Sorry about that - I will try to do better next time! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
llewxam Posted May 20, 2010 Share Posted May 20, 2010 Sorry about that - I will try to do better next time! hahaha!! I actually kinda switched things around to get around the issue differently, but will update the UDF abyway just in case. What I did was: $fontSize = 0 Do $findFontSize += 1 $findit = _StringSize($PlabelName, $findFontSize, Default, Default, "Arial", 160) Until $findit[3] > 55 $fontSize = $findFontSize - 1 Thankfully most of the terms used in the app aren't very large, but I want to make it not puke if at all possible Thanks again, again Ian My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 20, 2010 Author Moderators Share Posted May 20, 2010 llewxam, That will work because by going up in point value you should not hit an error state before finding a valid size. But as a matter of principle, it is a good idea to do some errorchecking whan you call complex UDFs (especially when you write them!). M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KaFu Posted May 21, 2010 Share Posted May 21, 2010 Nice approach , saved to toolbox for later use ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now