Возможности «включить» одной «галочкой» «автоматическое изменение размеров окна под размер дочерних окон при изменении их размера» нет.
Решение вопроса есть, но вы предпочитаете сетовать на отсутствие «фич» не имеющих к решению отношения.
text := "123"
index := 1
marginX := marginY := 5
SysGet, XBORDER , % SM_CXBORDER := 5
SysGet, YBORDER , % SM_CYBORDER := 6
SysGet, XEDGE , % SM_CXEDGE := 45
SysGet, YEDGE , % SM_CYEDGE := 46
borderX := XBORDER+XEDGE
borderY := YBORDER+YBORDER
Gui, +AlwaysOnTop -Border +ToolWindow +Disabled +LastFound +HWNDguiHWND
Gui, Color, Blue
Gui, Margin, %marginX%, %marginY%
Gui, font, s15 cWhite, Arial
Gui, Add, Text, vText, %text%
Gui, Show, NoActivate x5 y5
SetTimer, ChangeText_ResizeWindow, 50
return
ChangeText_ResizeWindow:
text .= Mod(++index, 12 )? index : "`n123"
pResult := GetTextSize(text, "Arial", "s15")
w := NumGet(pResult+0, 0, "UInt")
h := NumGet(pResult+0, 4, "UInt")
WinMove, ahk_id %guiHWND%,,,, w + marginX*2 + borderX*2, h + marginY*2 + borderY*2
GuiControl, Move, Text, w%w% h%h%
GuiControl,, Text, %text%
return
Esc::Exitapp
GetTextSize(String, FontName, Options)
{
static SIZE
coding := A_IsUnicode ? "W" : "A"
LOGPIXELSY := 90
FW_NORMAL := 400, FW_BOLD := 700
DEFAULT_CHARSET := 1
DEFAULT_QUALITY := OUT_DEFAULT_PRECIS := CLIP_DEFAULT_PRECIS := 0
if !RegExMatch(Options, "i).*s(\d+).*", Found)
{
MsgBox, Не задан размер шрифта!
Return
}
s := Found1
if !InStr(Options, "bold")
{
if !RegExMatch(Options, "i).*w(\d+).*", Found)
w := FW_NORMAL
Else
w := Found1
}
Else
w := FW_BOLD
if w not Between 1 and 1000
{
MsgBox, Неверно задан параметр w.`nДолжен быть в пределах от 1 до 1000
Return
}
italic := InStr(Options, "italic") > 0
underline := InStr(Options, "underline") > 0
strike := InStr(Options, "strike") > 0
hDC := DllCall("GetDC", UInt, 0)
nHeight := -DllCall("MulDiv", Int, s
, Int, DllCall("GetDeviceCaps", UInt, hDC, Int, LOGPIXELSY), Int, 72)
hFont := DllCall("CreateFont" . coding
, Int, nHeight, Int, 0
, Int, 0, Int, 0, Int, w
, UInt, italic, UInt, underline, UInt, strike
, UInt, DEFAULT_CHARSET, UInt, OUT_DEFAULT_PRECIS
, UInt, CLIP_DEFAULT_PRECIS, UInt, DEFAULT_QUALITY
, UInt, 0, Str, FontName)
hPrevObj := DllCall("SelectObject", UInt, hDC, UInt, hFont)
VarSetCapacity(Buf, 40)
DllCall("GetTextFace" . coding, UInt, hDC, Int, 40, Str, Buf)
if (Buf != FontName)
{
FreeMemory(hPrevObj, hDC, hFont)
MsgBox, Указанный шрифт не поддерживается системой!
Return
}
VarSetCapacity(SIZE, 8)
width = 0
Loop, parse, String, `n, `r
{
DllCall("GetTextExtentPoint32" . coding
, UInt, hDC, Str, A_LoopField, Int, StrLen(A_LoopField), Ptr, &SIZE)
width := (r := NumGet(SIZE, 0, "UInt")) > width ? r : width
n := A_Index
}
h := NumGet(SIZE, 4, "UInt")
NumPut(width, SIZE, "UInt"), NumPut(h*n, SIZE, 4, "UInt")
FreeMemory(hPrevObj, hDC, hFont)
Return &SIZE
}
FreeMemory(hPrevObj, hDC, hFont)
{
DllCall("SelectObject", UInt, hDC, UInt, hPrevObj)
DllCall("ReleaseDC", UInt, 0, UInt, hDC)
DllCall("DeleteObject", UInt, hFont)
}