$size = _StringSize('Строка, для которой нужно узнать размер (в пикселях)', 20, 600, 'Arial Black')
If IsArray($size) Then
MsgBox(0, '', 'Size = ' & $size[0] & ' x ' & $size[1])
EndIf
Func _StringSize($sString, $iSize = 9, $iWeight = 400, $sFontName = "")
Local $hWnd, $hGuiSwitch, $iCtrlID, $aCtrlSize, $aRetSize[2] = [0, 0]
$hWnd = GUICreate("StringExInternalWin", 0, 0, 0, 0, BitOR(0x80000000, 0x20000000), BitOR(0x00000080, 0x00000020))
$hGuiSwitch = GUISwitch($hWnd)
GUISetFont($iSize, $iWeight, -1, $sFontName, $hWnd)
$iCtrlID = GUICtrlCreateLabel($sString, 0, 0)
$aCtrlSize = ControlGetPos($hWnd, "", $iCtrlID)
GUIDelete($hWnd)
GUISwitch($hGuiSwitch)
If IsArray($aCtrlSize) Then
$aRetSize[0] = $aCtrlSize[2]; Width
$aRetSize[1] = $aCtrlSize[3]; Height
Return SetError(0, 0, $aRetSize)
EndIf
Return SetError(1, 0, $aRetSize)
EndFunc