#include <GUIConstantsEx.au3>
#include <winapi.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
Local $msg, $lbl, $lbl2
;Local $sTT = "This is a sentence which is unnecessarily long just so that I can demonstrate a way to wrap text and doesn't assume a fixed space font"
Local $sTT = "text 1 "
Local $sTT2 = "text 1 "
GUICreate("My GUI control tip") ; will create a dialog box that when displayed is centered
$lbl = GUICtrlCreateLabel("my label", 10, 20)
$lbl2 = GUICtrlCreateLabel("my label", 10, 60)
GUISetState()
SetTipWrapped($lbl, $sTT, 300)
SetTipWrapped($lbl2, $sTT2, 300)
; Run the GUI until the dialog is closed
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc ;==>Example
Func SetTipWrapped($iCtrl, $stext, $iMaxWid)
Local $n
GUICtrlSetTip($iCtrl, $stext);no wrapping to start
$stext = StringReplace($stext, @CRLF, @CR)
$stext = StringReplace($stext, @LF, @CR)
Local $hTT = _WinAPI_GetWindowDC(WinGetHandle($stext))
ConsoleWrite(Hex($hTT) & @CRLF)
Local $aS = WinGetPos($hTT)
Local $ts = _WinAPI_GetTextExtentPoint32($hTT, $stext)
Local $iLinestart = 1, $iLineLen, $iLastLen
Local $swrap = ''
While $iLinestart <= StringLen($stext); + 1
While $iLineLen + $iLinestart <= StringLen($stext)
If StringMid($stext, $iLinestart, 1) <> ' ' Then ExitLoop
$iLinestart += 1
WEnd
$iLineLen = 1
$iLastLen = 1
While $iLineLen + $iLinestart < StringLen($stext) + 1
If StringMid($stext, $iLinestart + $iLineLen, 1) = ' ' Or $iLineLen + $iLinestart >= StringLen($stext) Then
Local $mid = StringMid($stext, $iLinestart, $iLineLen)
$ts = _WinAPI_GetTextExtentPoint32($hTT, $mid)
If DllStructGetData($ts, 1) > $iMaxWid Then
If $iLastLen > 1 Then $iLineLen = $iLastLen
$swrap &= StringMid($stext, $iLinestart, $iLineLen) & @CR
$iLinestart += $iLineLen + 1
ExitLoop
EndIf
If $iLineLen + $iLinestart >= StringLen($stext) Then
$swrap &= StringMid($stext, $iLinestart, $iLineLen + 1)
$iLinestart += $iLineLen + 1
ExitLoop
EndIf
$iLastLen = $iLineLen
ElseIf StringMid($stext, $iLinestart + $iLineLen, 1) = @CR Then
$swrap &= StringMid($stext, $iLinestart, $iLineLen)
$iLinestart = $iLineLen + 1
ExitLoop
EndIf
$iLineLen += 1
WEnd
WEnd
GUICtrlSetTip($iCtrl, $swrap)
EndFunc ;==>SetTipWrapped