Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; ------------------------ ;
- ; TEST FORMATAGE AUTO ;
- ; ------------------------ ;
- #include-once
- #include <GUIConstantsEx.au3>
- #include <WinAPI.au3>
- #include <WindowsConstants.au3>
- #include <MsgBoxConstants.au3>
- #include <ButtonConstants.au3>
- #include <EditConstants.au3>
- #include <GUIConstantsEx.au3>
- #include <ColorConstants.au3>
- #include <Math.au3>
- Global $MyText = "Sed @ut@ perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, " & _
- "totam rem aperiam, eaque ipsa quae ab illo @inventore@ veritatis et quasi architecto beatae vitae dicta sunt explicabo. " & _
- "Nemo @enim@ ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos " & _
- "qui ratione @voluptatem@ sequi nesciunt. Neque porro quisquam est, qui @dolorem ipsum@ quia dolor sit amet, consectetur, " & _
- "adipisci velit, sed quia non numquam eius modi tempora incidunt @ut@ labore et dolore magnam aliquam quaerat voluptatem. " & _
- "Ut enim ad minima veniam, @quis@ nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi " & _
- "@consequatur@? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, " & _
- "vel illum qui dolorem @eum@ fugiat quo voluptas nulla pariatur?"
- Global $GUI = GUICreate("TEST",500,500)
- GUISetState(@SW_SHOW,$GUI)
- Global $LabelArray[0]
- TextToKWLabel($LabelArray,$MyText,50,50,400)
- While 1
- Sleep(100)
- If GUIGetMsg() == $GUI_EVENT_CLOSE Then
- GUIDelete($GUI)
- ExitLoop
- EndIf
- WEnd
- #cs ------------------------------------
- Hauteur = 16
- return heigth of the multi-label
- @Mot-clef@
- #ce ------------------------------------
- Func TextToKWLabel(ByRef $Array,$Text,$X,$Y,$Width)
- Local $temp,$dim,$rank=0
- Local $TextArray,$Length,$PosX=$X,$PosY=$Y
- If Not IsArray($Array) Then Return SetError(2, 0, 0)
- $TextArray = StringSplit($Text,"@")
- $Length = UBound($Array,1)
- ReDim $Array[$Length+1][_Max(UBound($Array,2),$TextArray[0]+1)]
- $Array[$Length][0] = $TextArray[0]
- For $i = 1 To $TextArray[0]
- If $TextArray[$i] == "" Then ContinueLoop
- $dim = GetStringDimension($TextArray[$i])
- If $PosX+$dim > $X+$Width And Not IsPair($i) Then
- $temp = SimpleStringSplit($TextArray[$i],$Width-$PosX)
- $rank += 1
- ReDim $Array[$Length+1][_Max(UBound($Array,2),$TextArray[0]+1+$rank)]
- $dim = GetStringDimension($temp[0])
- $Array[$Length][$i+$rank-1] = GUICtrlCreateLabel($temp[0],$PosX,$PosY,$dim,16)
- $PosX = $X
- $PosY += 16
- $dim = GetStringDimension($temp[1])
- $Array[$Length][$i+$rank] = GUICtrlCreateLabel($temp[1],$PosX,$PosY,$dim,16)
- $PosX += $dim
- ElseIf $PosX+$dim > $X+$Width Then
- $PosX = $X
- $PosY += 16
- $Array[$Length][$i+$rank] = GUICtrlCreateLabel($TextArray[$i],$PosX,$PosY,$dim,16)
- $PosX += $dim
- Else
- $Array[$Length][$i+$rank] = GUICtrlCreateLabel($TextArray[$i],$PosX,$PosY,$dim,16)
- $PosX += $dim
- EndIf
- If IsPair($i) Then
- GUICtrlSetFont(-1,8.5,0,4)
- GUICtrlSetColor(-1,$COLOR_BLUE)
- EndIf
- Next
- Return $PosY + 16
- EndFunc
- Func IsPair($X)
- Return Mod($X,2) == 0
- EndFunc
- ; Split a string in 2 splits while the string width is supp than a max width
- Func SimpleStringSplit($String,$Max)
- Local $Return[2]=["",""], $Range = 0
- Local $Words = StringSplit($String," ")
- For $i = 1 To $Words[0]
- If $Words[$i] == "" Then ContinueLoop
- $Range += GetStringDimension("" & $Words[$i] & " ")
- If $Range > $Max Then
- $Return[1] &= $Words[$i]
- If $i <> $Words[0] Then $Return[1] &= " "
- Else
- $Return[0] &= $Words[$i]
- If $i <> $Words[0] Then $Return[0] &= " "
- EndIf
- Next
- Return $Return
- EndFunc
- ; return Width (function in an autoit's example)
- Func GetStringDimension($sText)
- Local $hWnd = GUICreate("")
- Local $hDC = _WinAPI_GetDC($hWnd)
- Local $hFont = _SendMessage($hWnd, $WM_GETFONT)
- Local $hSelectObject = _WinAPI_SelectObject($hDC, $hFont)
- Local $tSIZE = _WinAPI_GetTextExtentPoint32($hDC, $sText)
- _WinAPI_SelectObject($hDC, $hSelectObject)
- _WinAPI_ReleaseDC($hWnd, $hDC)
- Local $aReturn = DllStructGetData($tSIZE, 1)
- GUIDelete($hWnd)
- Return $aReturn
- EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement