offlineJScript#1
Administradores
Sáb 23 Jul 2011, 19:51
UDF pronta para você adicionar textos "suspensos" em seus programas!
_FloatText.au3 - Código fonte:
Precisa desta UDF: https://notebook.forumbrasil.net/t69-_getsizeau3-udf#201
_FloatText.au3 - Código fonte:
- Código:
#include-once
#include <_GetSize.au3>
; #INDEX# ==========================================================================================================================================================
; Title .........: GuiFloatText
; AutoIt Version : 3.2.10++
; Language ......: English
; Description ...: Create an floating text.
; ==================================================================================================================================================================
; #CURRENT# ========================================================================================================================================================
;_GuiFloatText_Create
;_GuiFloatText_SetText
;_GuiFloatText_Delete
;_GuiFloatText_SetColor
;_GuiFloatText_SetState
;_GuiFloatText_SetPos
;_GuiFloatText_SetFont
; ==================================================================================================================================================================
; #INTERNAL_USE_ONLY#===============================================================================================================================================
;__SetTextToWindow
; ==================================================================================================================================================================
; #VARIABLES# ===================================================================================================================
Global $aGFT_CONTROLSID[1][9]
; ===============================================================================================================================
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_Create
; Description ...: Get the size (in pixels) of an text.
; Syntax.........: _GuiFloatText_Create( "text", left, top [, size [, weight [, fontname [, setTrans]]]] )
; Parameters ....: Text - The text to evaluate the size.
; left - The left of the control.
; top - The top of the control.
; 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).
; setTrans - [optional] Sets the transparency of a Text.
; Requirement(s).:
; Return values .: Success - Returns the identifier (controlID) of the new control.
; Failure - Returns 0.
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_Create($sTitle, $sText)
; ===============================================================================================================================
Func _GuiFloatText_Create($sText, $iLeft, $iTop, $iSize = 9, $iWeight = 400, $sFontName = "", $iSetTrans = 255)
Local $hWnd, $hGetDC, $hGuiSwitch, $aStrSize
Local $hCreateFont, $hOldFont
Local $hRegion1, $sStruct, $hRegion2
If $sText = "" Then $sText = " "
If $sFontName = "" Then $sFontName = "Microsoft Sans Serif"
$aStrSize = _StringSize($sText, $iSize, $iWeight, $sFontName)
If @error Then Return 0
$iWidth = $aStrSize[0] + $aStrSize[1] + $iSize
$iHeight = $aStrSize[1]
$hWnd = GUICreate("AutoItOverlayedWindow - " & Random(100, 1000), $iWidth, $iHeight, $iLeft, _
$iTop, 0x80000000, BitOR(0x00000008, 0x00000080))
$hGuiSwitch = GUISwitch($hWnd)
GUISetBkColor(0x000000)
If $iSetTrans < 255 Then WinSetTrans($hWnd, "", $iSetTrans)
;__SetTextToWindow($hWnd, $sText, $iHeight, $iSize, $iWeight, $sFontName)
GUISwitch($hGuiSwitch)
For $i = 1 To $aGFT_CONTROLSID[0][0]
If $aGFT_CONTROLSID[$i][0] = $hWnd Then
$aGFT_CONTROLSID[$i][0] = $hWnd
$aGFT_CONTROLSID[$i][1] = $sText
$aGFT_CONTROLSID[$i][2] = $iLeft
$aGFT_CONTROLSID[$i][3] = $iTop
$aGFT_CONTROLSID[$i][4] = $iWidth
$aGFT_CONTROLSID[$i][5] = $iHeight
$aGFT_CONTROLSID[$i][6] = $iSize
$aGFT_CONTROLSID[$i][7] = $iWeight
$aGFT_CONTROLSID[$i][8] = $sFontName
Return $hWnd
EndIf
Next
ReDim $aGFT_CONTROLSID[UBound($aGFT_CONTROLSID, 1) + 1][9]
$aGFT_CONTROLSID[0][0] += 1
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][0] = $hWnd
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][1] = $sText
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][2] = $iLeft
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][3] = $iTop
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][4] = $iWidth
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][5] = $iHeight
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][6] = $iSize
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][7] = $iWeight
$aGFT_CONTROLSID[$aGFT_CONTROLSID[0][0]][8] = $sFontName
Return $hWnd
EndFunc ;==>_GuiFloatText_Create
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_SetText
; Description ...: Set/change the float text.
; Syntax.........: _GuiFloatText_SetText( controlID, "Text" )
; Parameters ....: controlID - The controlID.
; Text - The text to evaluate the size.
; Requirement(s).:
; Return values .: Success - Returns 1
; Failure - Returns 0
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_SetText($CtrlID, $sText)
; ===============================================================================================================================
Func _GuiFloatText_SetText($hWnd, $sText)
Local $hGetDC, $iWidth, $iHeight
Local $hCreateFont, $hOldFont
Local $iSize, $iWeight, $sFontName
Local $hRegion1, $sStruct, $hRegion2
If Not WinExists($hWnd, "") Then Return 0
For $i = 1 To $aGFT_CONTROLSID[0][0]
If $aGFT_CONTROLSID[$i][0] <> $hWnd Then ContinueLoop
$iSize = $aGFT_CONTROLSID[$i][6]
$iWeight = $aGFT_CONTROLSID[$i][7]
$sFontName = $aGFT_CONTROLSID[$i][8]
$aStrSize = _StringSize($sText, $iSize, $iWeight, $sFontName)
If @error Then ExitLoop
$iWidth = $aStrSize[0] + $aStrSize[1] + $iSize
$iHeight = $aStrSize[1]
WinMove($hWnd, "", $aGFT_CONTROLSID[$i][2], $aGFT_CONTROLSID[$i][3], $iWidth, $iHeight)
$aGFT_CONTROLSID[$i][1] = $sText
$aGFT_CONTROLSID[$i][4] = $iWidth
$aGFT_CONTROLSID[$i][5] = $iHeight
$aGFT_CONTROLSID[$i][6] = $iSize
$aGFT_CONTROLSID[$i][7] = $iWeight
$aGFT_CONTROLSID[$i][8] = $sFontName
__SetTextToWindow($hWnd, $sText, $iHeight, $iSize, $iWeight, $sFontName)
Return 1
Next
Return SetError(0, 0, 0)
EndFunc ;==>_GuiFloatText_SetText
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_Delete
; Description ...: Delete the float control ID.
; Syntax.........: _GuiFloatText_Create( controlID )
; Parameters ....: controlID - The controlID.
; Requirement(s).:
; Return values .: Success - Returns 1
; Failure - Returns 0
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_Delete($CtrlID)
; ===============================================================================================================================
Func _GuiFloatText_Delete($hWnd)
Local $aClone[1][9]
If Not WinExists($hWnd, "") Then Return 0
For $i = 1 To $aGFT_CONTROLSID[0][0]
If $aGFT_CONTROLSID[$i][0] = $hWnd Then ContinueLoop
ReDim $aClone[UBound($aClone, 1) + 1][9]
$aClone[0][0] += 1
For $j = 0 To 4
$aClone[$aClone[0][0]][$j] = $aGFT_CONTROLSID[$i][$j]
Next
Next
$aGFT_CONTROLSID = $aClone
$aClone = 0
Return GUIDelete($hWnd)
EndFunc ;==>_GuiFloatText_Delete
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_SetColor
; Description ...: Set the color of a float text.
; Syntax.........: _GuiFloatText_SetColor( controlID, color )
; Parameters ....: controlID - The text to evaluate the size.
; color - The color to be set.
; Requirement(s).:
; Return values .: Success - Returns 1
; Failure - Returns 0
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_SetColor($CtrlID, $iColor)
; ===============================================================================================================================
Func _GuiFloatText_SetColor($hWnd, $iColor)
If Not WinExists($hWnd, "") Then Return 0
Return GUISetBkColor($iColor, $hWnd)
EndFunc ;==>_GuiFloatText_SetColor
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_SetState
; Description ...: Set the state of an float text.
; Syntax.........: _GuiFloatText_SetState( controlID [, state ] )
; Parameters ....: controlID - The controlID.
; state - The state to be set of the control.
; Requirement(s).:
; Return values .: Success - Returns 1
; Failure - Returns 0
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_SetState($CtrlID)
; ===============================================================================================================================
Func _GuiFloatText_SetState($hWnd, $iState = @SW_SHOW)
If Not WinExists($hWnd, "") Then Return 0
Return GUISetState($iState, $hWnd)
EndFunc ;==>_GuiFloatText_SetState
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_SetPos
; Description ...: Set the position of an float text.
; Syntax.........: _GuiFloatText_SetPos( controlID, left, top )
; Parameters ....: controlID- The controlID.
; left - The left of the control. To leave in default position use -1.
; top - The top of the control. To leave in default position use -1.
; Requirement(s).:
; Return values .: Success - Returns 1
; Failure - Returns 0 if control is not found.
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_SetPos($CtrlID, -1, 20)
; ===============================================================================================================================
Func _GuiFloatText_SetPos($hWnd, $iLeft = -1, $iTop = -1)
If Not WinExists($hWnd, "") Then Return 0
For $i = 1 To $aGFT_CONTROLSID[0][0]
If $aGFT_CONTROLSID[$i][0] <> $hWnd Then ContinueLoop
If $iLeft > -1 Then $aGFT_CONTROLSID[$i][2] = $iLeft
If $iTop > -1 Then $aGFT_CONTROLSID[$i][3] = $iTop
Return WinMove($hWnd, "", $iLeft, $iTop)
Next
Return SetError(0, 0, 0)
EndFunc
; #FUNCTION# ====================================================================================================================
; Name...........: _GuiFloatText_SetFont
; Description ...: Set the fonte of an float text.
; Syntax.........: _GuiFloatText_SetFont( "text", left, top [, size [, weight [, fontname [, setTrans]]]] )
; Parameters ....: Text - The text to evaluate the size.
; left - The left of the control.
; top - The top of the control.
; width - [[optional] The width of the control (default is the previously used width).
; height - [optional] The height of the control (default is the previously used height).
; setTrans - [optional] Sets the transparency of a Text.
; Requirement(s).:
; Return values .: Success - Returns 1
; Failure - Returns 0
; Author ........: jscript
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........;
; Example .......; _GuiFloatText_SetFont($hWnd, 9, 400, 0, "Arial")
; ===============================================================================================================================
Func _GuiFloatText_SetFont($hWnd, $iSize = 9, $iWeight = 400, $iAttribute = 0, $sFontName = "")
Local $hGetDC, $iWidth, $iHeight
Local $hCreateFont, $hOldFont, $sText
Local $hRegion1, $sStruct, $hRegion2
If Not WinExists($hWnd, "") Then Return 0
If $sFontName = "" Then $sFontName = "Microsoft Sans Serif"
For $i = 1 To $aGFT_CONTROLSID[0][0]
If $aGFT_CONTROLSID[$i][0] <> $hWnd Then ContinueLoop
$aStrSize = _StringSize($aGFT_CONTROLSID[$i][1], $iSize, $iWeight, $sFontName)
If @error Then ExitLoop
$iWidth = $aStrSize[0] + $aStrSize[1] + $iSize
$iHeight = $aStrSize[1]
If ($iWidth <> $aGFT_CONTROLSID[$i][4]) Or ($iHeight <> $aGFT_CONTROLSID[$i][5]) Then _
WinMove($hWnd, "", $aGFT_CONTROLSID[$i][2], $aGFT_CONTROLSID[$i][3], $iWidth, $iHeight)
$sText = $aGFT_CONTROLSID[$i][1]
$aGFT_CONTROLSID[$i][4] = $iWidth
$aGFT_CONTROLSID[$i][5] = $iHeight
$aGFT_CONTROLSID[$i][6] = $iSize
$aGFT_CONTROLSID[$i][7] = $iWeight
$aGFT_CONTROLSID[$i][8] = $sFontName
__SetTextToWindow($hWnd, $sText, $iHeight, $iSize, $iWeight, $sFontName)
Return 1
Next
Return SetError(0, 0, 0)
EndFunc ;==>_GuiFloatText_SetFont
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __SetTextToWindow
; Description ...: Set transparent text to window.
; Syntax.........: __SetTextToWindow( winhandle, "text", size, weight, fontname )
; Author ........: Larry
; Modified by ...: João Carlos (jscript)
; ===============================================================================================================================
Func __SetTextToWindow($hWnd, $sText, $iHeight, $iSize, $iWeight, $sFontName)
Local $hGetDC, $hCreateFont, $hOldFont
Local $hRegion1, $sStruct, $hRegion2
$hGetDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $hWnd)
$hCreateFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $iHeight, "int", $iSize / 1.7, "int", 0, _
"int", 0, "int", $iWeight, "int", 0, "int", 0, "int", 0, "int", 0, "int", 2, "int", 0, _
"int", 2, "int", 1, "str", $sFontName)
$hOldFont = DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hGetDC[0], "hwnd", $hCreateFont[0])
DllCall("gdi32.dll", "int", "BeginPath", "int", $hGetDC[0])
DllCall("gdi32.dll", "int", "TextOut", "int", $hGetDC[0], "int", 0, "int", 0, _
"str", $sText, "int", StringLen($sText))
DllCall("gdi32.dll", "int", "EndPath", "int", $hGetDC[0])
$hRegion1 = DllCall("gdi32.dll", "hwnd", "PathToRegion", "int", $hGetDC[0])
$sStruct = DllStructCreate("int;int;int;int")
DllCall("gdi32.dll", "int", "GetRgnBox", "hwnd", $hRegion1[0], "ptr", DllStructGetPtr($sStruct))
$hRegion2 = DllCall("gdi32.dll", "hwnd", "CreateRectRgnIndirect", "ptr", DllStructGetPtr($sStruct))
DllCall("gdi32.dll", "int", "CombineRgn", "hwnd", $hRegion2[0], "hwnd", $hRegion2[0], _
"hwnd", $hRegion1[0], "int", 3)
DllCall("user32.dll", "int", "SetWindowRgn", "hwnd", $hWnd, "hwnd", $hRegion2[0], "int", 1)
DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $hRegion1[0])
DllCall("gdi32.dll", "int", "DeleteObject", "hwnd", $hRegion2[0])
DllCall("gdi32.dll", "int", "SelectObject", "int", $hGetDC[0], "hwnd", $hOldFont[0])
DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hWnd, "int", $hGetDC[0])
Return 1
EndFunc ;==>__SetTextToWindow
Precisa desta UDF: https://notebook.forumbrasil.net/t69-_getsizeau3-udf#201