#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
_GDIPlus_Startup()
Global $hGUI = GUICreate("Test", 800, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX), $WS_EX_COMPOSITED)
Global $idGroup = GUICtrlCreateGroup("", 224, 0, 569, 92)
Global $sLabel = "Scale this label dynamically"
Global $fFontsize, $sFont = "Impact"
Global $idLabel = GUICtrlCreateLabel($sLabel, 228, 14, 563, 76, $SS_CENTER)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
GUICtrlSetColor(-1, 0x000080)
Global $idLabelDummy = GUICtrlCreateLabel("", 228, 14, 563, 76)
GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
Resize
_Font
()
GUISetState(@SW_SHOW)
Global $aWDim = WinGetPos($hGUI)
Global $w = $aWDim[2], $h = $aWDim[3]
GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
GUIRegisterMsg($WM_GETMINMAXINFO, "")
GUIRegisterMsg($WM_SIZE, "")
GUIDelete($hGUI)
_GDIPlus_Shutdown()
Exit
Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
Resize
_Font
()
EndSwitch
WEnd
Func Resize
_Font
()
$aPOS = ControlGetPos($hGUI, "", $idLabelDummy)
GUICtrlSetPos($idLabel, $aPOS[0] + 2, $aPOS[1] + 8, $aPOS[2] - 6, $aPOS[3] - 12)
$fFontsize = CalcFontSize
($sLabel, $aPOS[2] - 6, $aPOS[3] - 12, $sFont)
GUICtrlSetFont($idLabel, $fFontsize, 400, 0, $sFont, 5)
EndFunc
Func CalcFontSize
($sString, $iW, $iH, $sFont)
Local $aResult, $hFont, $i, $iLen = StringLen($sString)
Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(WinGetHandle(AutoItWinGetTitle()))
Local $tRectF = DllStructCreate($tagGDIPRECTF)
Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
Local $hFormat = _GDIPlus_StringFormatCreate()
Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
$i = 1
Do
$hFont = _GDIPlus_FontCreate($hFamily, $i, 0)
$aResult = DllCall($ghGDIPDll, "int", "GdipMeasureString", "handle", $hGfx, "wstr", $sString, "int", -1, "handle", $hFont, "struct*", $tLayout, "handle", $hFormat, "struct*", $tRectF, "int*", 0, "int*", 0)
_GDIPlus_FontDispose($hFont)
If $aResult[8] < $iLen Or $aResult[9] = 2 Or $i > $iH / 1.45 Then ExitLoop
$i += 1
Until False
_GDIPlus_FontFamilyDispose($hFamily)
_GDIPlus_StringFormatDispose($hFormat)
_GDIPlus_GraphicsDispose($hGfx)
$tLayout = 0
Return $i
EndFunc
Func WM
_SIZE
($hWnd, $Msg, $wParam, $lParam)
Resize
_Font
()
Return "GUI_RUNDEFMSG"
EndFunc
Func WM
_GETMINMAXINFO
($hWnd, $Msg, $wParam, $lParam)
Local $minmaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
DllStructSetData($minmaxinfo, 7, $w) ; min W
DllStructSetData($minmaxinfo, 8, $h) ; min H
Return "GUI_RUNDEFMSG"
EndFunc ;==>WM_GETMINMAXINFO
But you can try it.