offlineJScript#1
Administradores
Sáb 23 Jul 2011, 19:48
Código fonte:
- Código:
#include-once
; #INDEX# =======================================================================================================================
; Title .........: _GetSize
; AutoIt Version.: 3.2.12++
; Language.......: English
; Description ...: Get size of various elements (string, image...).
; Version .......: 1.08.2209.2600
; Remarks .......:
; Credits .......: jscript
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_StringSize
;_ImageSize
; ===============================================================================================================================
; #INTERNAL_USE_ONLY#============================================================================================================
; ===============================================================================================================================
; #VARIABLES# ===================================================================================================================
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _StringSize
; Description ...: Returns the size (in pixels) of an string.
; Syntax.........: _StringSize( "string" [, size [, weight [, fontname ]]] )
; Parameters ....: string - The string to evaluate the size.
; Size - [Optional] Fontsize (default is 9).
; Weight - [Optional] Font weight (default 400 = normal).
; FontName - [Optional] Font to use (OS default GUI font is used if the font is "" or is not found).
; Requirement(s).:
; Return values .: Success - Returns a 2-element array containing the following information:
; $array[0] = Width
; $array[1] = Height
; Failure - Returns the same array with 0 and sets @error to 1.
; Author ........: jscript
; Example .......: _StringSize( "Text" )
; ===============================================================================================================================
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)
If $iSize = 65535 Then ; Used by _ImageSize
$iCtrlID = GUICtrlCreatePic($sString, 0, 0, 0, 0)
Else
GUISetFont($iSize, $iWeight, -1, $sFontName, $hWnd)
$iCtrlID = GUICtrlCreateLabel($sString, 0, 0)
EndIf
$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 ;==>_StringSize
; #FUNCTION# ====================================================================================================================
; Name...........: _ImageSize
; Description ...: Get the size (in pixels) of an picture.
; Syntax.........: _ImageSize( filename )
; Parameters ....: FileName - filename of the picture to be evaluete size: supported types BMP, JPG, GIF(but not animated).
; Requirement(s).: _StringSize
; Return values .: Success - Returns a 2-element array containing the following information:
; $array[0] = Width
; $array[1] = Height
; Failure - Returns the same array with 0 and sets @error to 1.
; Author ........: jscript
; Example .......: _ImageSize( @Scriptdir & "\image.bmp" )
; ===============================================================================================================================
Func _ImageSize($FileName)
Return _StringSize($FileName, 65535)
EndFunc ;==>_ImageSize