Hey, ich möchte euch mal meine erste richtige UDF vorstellen. Hierbei handelt es sich um eine UDF mit der man Fenster erstellen kann die unten rechts über der Taskleiste erscheinen wie in Steam o. Skype o.ä.
Funktionen
;_PopUpGUI_Create()
;_PopUpGUI_AddImg()
;_PopUpGUI_AddText()
;_PopUpGUI_SetBKColor()
;_PopUpGUI_SetGradientBk()
;_PopUpGUI_Slide()
;_PopUpGUI_Fade()
;_PopUpGUI_Shutdown()
UDF
; #Includes# ======================================================================================
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <StaticConstants.au3>
#include-once
; =================================================================================================
; #Globale Variablen# =============================================================================
Global Const $SPI_GETWORKAREA = 48
Global $_hMainGUI, $_hLabel, $hGraphic, $widthheight, $hGraphicsText, $hGraphic
Global $aGDIText[1][8], $aGDIImg[1][6], $aDisposalImg[1][2], $aDisposalText[1][6]
; =================================================================================================
_GDIPlus_Startup()
;Functions ========================================================================================
;_PopUpGUI_Create()
;_PopUpGUI_AddImg()
;_PopUpGUI_AddText()
;_PopUpGUI_SetBKColor()
;_PopUpGUI_SetGradientBk()
;_PopUpGUI_Slide()
;_PopUpGUI_Fade()
;_PopUpGUI_Shutdown()
; =================================================================================================
; #Not Working# ===================================================================================
;_PopUpGUI_DeleteImg() - Not Fixed
;_PopUpGUI_DeleteText() - Not Fixed
; =================================================================================================
;Internal Use Only!! ==============================================================================
;_ReDraw()
;_Sleep()
;GradientFill()
;_GetDeskWorkArea()
; =================================================================================================
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_Create()
; Description ...: Creates the PopUp GUI
; Syntax ........: _PopUpGUI_Create([$iWidth = 300[, $iHeight = 200[, $bOnTop = True]]])
; Parameters ....: $iWidth - [optional] Width of the GUI (default:300)
; $iHeight - [optional] Height of the GUI (default:200)
; $bOnTop - [optional] (default:True)
; |True = GUI will be on Top
; |False = GUI will not be on Top
; Return values .: Success
; |Handle to the GUI
; Failure
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_Create($iWidth = 300, $iHeight = 200, $bOnTop = True)
If Not IsInt($iWidth) Or Not IsInt($iHeight) Then Return SetError(1, 0, -1)
$aWorkArea = _GetDeskWorkArea()
$iLeft = $aWorkArea[2] - $iWidth
$iTop = $aWorkArea[3] - $iHeight
If $bOnTop Then
$1 = $WS_EX_TOPMOST
Else
$1 = ""
EndIf
$_hMainGUI = GUICreate("", $iWidth, $iHeight, $iLeft, $iTop, $WS_POPUP, $WS_EX_TOOLWINDOW + $1)
$hGraphic = GUICtrlCreateGraphic(0, 0, $iWidth, $iHeight)
$widthheight = GUICtrlCreateLabel($iWidth & "," & $iHeight, -100, -100, -100, -100)
GUICtrlSetState($widthheight, $GUI_HIDE)
GUISetState(@SW_SHOW)
WinSetTrans($_hMainGUI, "", 0)
Return $_hMainGUI
EndFunc ;==>_PopUpGUI_Create
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_AddImg()
; Description ...: Add an Image to the PopUp GUI
; Syntax ........: _PopUpGUI_AddImg($_hMainGUI, $hImg, $x1, $y1, $x2, $y2)
; Parameters ....: $_hMainGUI - Handle return by _PopUpGUI_Create()
; $hImg - Path to the Image File
; $x1 - x position of the Image
; $y1 - y position of the Image
; $x2 - Width of the Image
; $y2 - Height of the Image
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_AddImg($_hMainGUI, $hImg, $x1, $y1, $x2, $y2)
If Not IsHWnd($_hMainGUI) Then Return SetError(1, 0, -1)
If Not IsInt($x1) Or Not IsInt($y1) Or Not IsInt($x2) Or Not IsInt($y2) Then Return SetError(3, 0, 3)
$_C = UBound($aDisposalImg) - 1
$aDisposalImg[$_C][0] = _GDIPlus_GraphicsCreateFromHWND($_hMainGUI)
$aDisposalImg[$_C][1] = _GDIPlus_ImageLoadFromFile($hImg)
ReDim $aDisposalImg[$_C + 1][2]
_GDIPlus_GraphicsDrawImageRect($aDisposalImg[$_C][0], $aDisposalImg[$_C][1], $x1, $y1, $x2, $y2)
$_Count = UBound($aGDIImg)
$aGDIImg[$_Count - 1][0] = $aDisposalImg[$_C][0]
$aGDIImg[$_Count - 1][1] = $aDisposalImg[$_C][1]
$aGDIImg[$_Count - 1][2] = $x1
$aGDIImg[$_Count - 1][3] = $y1
$aGDIImg[$_Count - 1][4] = $x2
$aGDIImg[$_Count - 1][5] = $y2
ReDim $aGDIImg[$_Count][6]
EndFunc ;==>_PopUpGUI_AddImg
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_AddText()
; Description ...: Adds a Text to the PopUp GUI
; Syntax ........: _PopUpGUI_AddText($_hMainGUI, $sText, $x1, $y1)
; Parameters ....: $_hMainGUI - Handle return by _PopUpGUI_Create()
; $sText - Text to add
; $x1 - x position of the Text
; $y1 - y position of the Text
; $hFont - Font of the Text
; $hColor - Color of the Text
; $hSize - Size of the Text
; $hStyle - Style of the Text
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_AddText($_hMainGUI, $sText, $x1, $y1, $hFont = "Arial", $hColor = 0xFF000000, $hSize = 12, $hStyle = "Normal")
Switch $hStyle
Case "Normal"
$Style = 0
Case "Bold"
$Style = 1
Case "Italic"
$Style = 2
Case "Underlined"
$Style = 4
Case "Strikethrough"
$Style = 8
Case 0
$Style = 0
Case 1
$Style = 1
Case 2
$Style = 2
Case 4
$Style = 4
Case 8
$Style = 8
EndSwitch
$_C = UBound($aDisposalText) - 1
$aDisposalText[$_C][0] = _GDIPlus_GraphicsCreateFromHWND($_hMainGUI)
$aDisposalText[$_C][1] = _GDIPlus_BrushCreateSolid($hColor)
$aDisposalText[$_C][2] = _GDIPlus_StringFormatCreate()
$aDisposalText[$_C][3] = _GDIPlus_FontFamilyCreate($hFont)
$aDisposalText[$_C][4] = _GDIPlus_FontCreate($aDisposalText[$_C][3], $hSize, $Style)
$tRect = _GDIPlus_RectFCreate($x1, $y1, 0, 0)
ReDim $aDisposalText[$_C + 1][5]
$aInfo = _GDIPlus_GraphicsMeasureString($aDisposalText[$_C][0], $sText, $aDisposalText[$_C][4], $tRect, $aDisposalText[$_C][2])
_GDIPlus_GraphicsDrawStringEx($aDisposalText[$_C][0], $sText, $aDisposalText[$_C][4], $aInfo[0], $aDisposalText[$_C][2], $aDisposalText[$_C][1])
$_Count = UBound($aGDIText)
$aGDIText[$_Count - 1][0] = $aDisposalText[$_C][0]
$aGDIText[$_Count - 1][1] = $aDisposalText[$_C][1]
$aGDIText[$_Count - 1][2] = $aDisposalText[$_C][2]
$aGDIText[$_Count - 1][3] = $aDisposalText[$_C][3]
$aGDIText[$_Count - 1][4] = $aDisposalText[$_C][4]
$aGDIText[$_Count - 1][5] = $tRect
$aGDIText[$_Count - 1][6] = $aInfo[0]
$aGDIText[$_Count - 1][7] = $sText
ReDim $aGDIText[$_Count][8]
EndFunc ;==>_PopUpGUI_AddText
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_SetBKColor()
; Description ...: Sets the Background Color of the PopUp GUI
; Syntax ........: _PopUpGUI_SetBKColor($_hMainGUI, $hBkColor)
; Parameters ....: $_hMainGUI -
; $hBkColor - Hexcode for the BackgroundColor
; Return values .: Success
; Failure
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_SetBKColor($_hMainGUI, $hBkColor)
If Not IsHWnd($_hMainGUI) Then Return SetError(1, 0, -1)
If Not StringLeft($hBkColor, 2) = '0x' Then Return SetError(2, 0, 2)
$_widthheight = StringSplit(GUICtrlRead($widthheight), ",")
GUICtrlSetState($hGraphic, $GUI_HIDE)
GUISetBkColor($hBkColor, $_hMainGUI)
_ReDraw()
EndFunc ;==>_PopUpGUI_SetBKColor
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_SetGradientBk()
; Description ...: Sets a Gradient Background Color
; Syntax ........: _PopUpGUI_SetGradientBk($_hMainGUI, $aFirstColor, $aSecondColor)
; Parameters ....: $_hMainGUI - Handle to the PopUp GUI
; $aFirstColor - Array of the First Color
; |Array[0] = Red
; |Array[1] = Blue
; |Array[2] = Green
; $aSecondColor - Array of the Second Color
; |Array[0] = Red
; |Array[1] = Blue
; |Array[2] = Green
; Return values .: Success
; Failure
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_SetGradientBk($_hMainGUI, $aFirstColor, $aSecondColor)
If Not IsHWnd($_hMainGUI) Then Return SetError(1, 0, -1)
If Not IsArray($aFirstColor) Or Not IsArray($aSecondColor) Then Return SetError(2, 0, 2)
$wh = GUICtrlRead($widthheight)
$_wh = StringSplit($wh, ",")
GUICtrlSetState($hGraphic, $GUI_SHOW)
GradientFill($hGraphic, 0, 0, $_wh[1], $_wh[2], $aFirstColor, $aSecondColor)
GUICtrlSetGraphic($hGraphic, $GUI_GR_REFRESH)
_ReDraw()
EndFunc ;==>_PopUpGUI_SetGradientBk
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_Slide()
; Description ...: Slides the GUI in and out
; Syntax ........: _PopUpGUI_Slide($_hMainGUI[, $iTime = 2000])
; Parameters ....: $_hMainGUI - Handle to the PopUp GUI
; $iTime - [optional] Time in ms between Slide In and Slide Out (default:2000)
; Return values .: Success
; Failure
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_Slide($_hMainGUI, $iTime = 2000)
If Not IsHWnd($_hMainGUI) Then SetError(1, 0, -1)
$_wh = StringSplit(GUICtrlRead($widthheight), ",")
$aWorkArea = _GetDeskWorkArea()
WinSetTrans($_hMainGUI, "", 0)
GUISetState(@SW_SHOW, $_hMainGUI)
For $sa = 0 To 100
_ReDraw()
WinMove($_hMainGUI, "", $aWorkArea[2] - $_wh[1], $aWorkArea[3] - ($_wh[2] / 100 * $sa))
WinSetTrans($_hMainGUI, "", $sa * 2.55)
_Sleep(8)
Next
Sleep($iTime)
For $sa = 100 To 0 Step -1
WinMove($_hMainGUI, "", $aWorkArea[2] - $_wh[1], ($aWorkArea[3]) - ($_wh[2] / 100 * $sa))
WinSetTrans($_hMainGUI, "", $sa * 2.55)
_Sleep(8)
Next
WinMove($_hMainGUI, "", $aWorkArea[2] - $_wh[1], $aWorkArea[3] - $_wh[2])
EndFunc ;==>_PopUpGUI_Slide
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_Fade()
; Description ...: Fades in the PopUp GUI
; Syntax ........: _PopUpGUI_Fade($_hMainGUI[, $iTime = 2500])
; Parameters ....: $_hMainGUI - Handle to the PopUp GUI
; $iTime - [optional] Time in ms between Fade In and Fade Out (default:2500)
; Return values .: Success
; Failure
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_Fade($_hMainGUI, $iTime = 2500)
If Not IsHWnd($_hMainGUI) Then Return SetError(1, 0, -1)
For $i = 0 To 255
WinSetTrans($_hMainGUI, "", $i)
_Sleep(4)
Next
Sleep($iTime)
For $y = 255 To 0 Step -1
WinSetTrans($_hMainGUI, "", $y)
_Sleep(4)
Next
EndFunc ;==>_PopUpGUI_Fade
; #FUNCTION# ======================================================================================
; Name ..........: _PopUpGUI_Shutdown()
; Description ...: Release GDI+ Resources
; Syntax ........: _PopUpGUI_Shutdown()
; Parameter .....: None
; Return values .: Success
; Failure
; Author ........: Higggiii
; =================================================================================================
Func _PopUpGUI_Shutdown()
$_C1 = UBound($aDisposalImg) - 1
If $aDisposalImg[0][0] <> "" Then
For $b = 0 To $_C1
_GDIPlus_ImageDispose($aDisposalImg[$b][1])
_GDIPlus_GraphicsDispose($aDisposalImg[$b][0])
Next
EndIf
$_C2 = UBound($aDisposalText) - 1
If $aDisposalText[0][0] <> "" Then
For $c = 0 To $_C2
_GDIPlus_BrushDispose($aDisposalText[$c][1])
_GDIPlus_StringFormatDispose($aDisposalText[$c][2])
_GDIPlus_FontFamilyDispose($aDisposalText[$c][3])
_GDIPlus_FontDispose($aDisposalText[$c][4])
_GDIPlus_GraphicsDispose($aDisposalText[$c][0])
Next
EndIf
_GDIPlus_Shutdown()
EndFunc ;==>_PopUpGUI_Shutdown
; #Need Fix# ======================================================================================
;~ Func _PopUpGUI_DeleteImg($_hMainGUI, $hImg)
;~ If Not IsHWnd($_hMainGUI) Then Return SetError(1, 0, -1)
;~ _GDIPlus_GraphicsClear($hImg)
;~ GUICtrlSetGraphic($hGraphic, $GUI_GR_REFRESH)
;~ _ReDraw()
;~ EndFunc
;~ Func _PopUpGUI_DeleteText($_hMainGUI, $hText)
;~ If Not IsHWnd($_hMainGUI) Then SetError(1, 0, -1)
;~ _GDIPlus_GraphicsClear($hGraphicsText)
;~ GUICtrlSetGraphic($hGraphic, $GUI_GR_REFRESH)
;~ _ReDraw()
;~ EndFunc
; =================================================================================================
; #Internal use Only# =============================================================================
[/autoit] [autoit][/autoit] [autoit]Func _ReDraw()
$_Count1 = UBound($aGDIImg)
If $aGDIImg[0][0] <> "" Then
For $i = 0 To $_Count1 - 1
_GDIPlus_GraphicsDrawImageRect($aGDIImg[$i][0], $aGDIImg[$i][1], $aGDIImg[$i][2], $aGDIImg[$i][3], $aGDIImg[$i][4], $aGDIImg[$i][5])
Next
EndIf
$_Count2 = UBound($aGDIText)
If $aGDIText[0][0] <> "" Then
For $a = 0 To $_Count2 - 1
_GDIPlus_GraphicsDrawStringEx($aGDIText[$a][0], $aGDIText[$a][7], $aGDIText[$a][4], $aGDIText[$a][6], $aGDIText[$a][2], $aGDIText[$a][1])
Next
EndIf
EndFunc ;==>_ReDraw
; #FUNCTION# ======================================================================================
; Name ..........: _Sleep()
; Description ...: Sleep for Ticks under 10 ms
; Syntax ........: _Sleep($iTicks)
; Parameters ....: $iTicks - Time in ms < 10
; Return values .: Success
; Failure
; Author ........: [email='Oscar@autoit.de'][/email]
; =================================================================================================
Func _Sleep($iTicks)
Local $iTimer = TimerInit()
Do
Until TimerDiff($iTimer) > $iTicks
EndFunc ;==>_Sleep
;===============================================================================
;
; Description: Gibt die Ausmasse des Desktop ohne Taskleiste zurück
; Parameter(s): keine
; Requirement(s): keine
; Return Value(s): bei Erfolg: Array{0] = links
; Array[1] = oben
; Array[2] = rechts
; Array[3] = unten
; bei Fehler: Leerstring und @error = 1
; Author(s): bernd670
;
;===============================================================================
Func _GetDeskWorkArea()
Dim $ds_rect = DllStructCreate("uint;uint;uint;uint"), $RetVal[4]
$Result = DllCall("user32.dll", "long", "SystemParametersInfo" _
, "long", $SPI_GETWORKAREA _
, "long", 0 _
, "ptr", DllStructGetPtr($ds_rect) _
, "long", 0 _
)
If @error Then
SetError(1)
Return ""
EndIf
$RetVal[0] = DllStructGetData($ds_rect, 1) ; left
$RetVal[1] = DllStructGetData($ds_rect, 2) ; top
$RetVal[2] = DllStructGetData($ds_rect, 3) ; right
$RetVal[3] = DllStructGetData($ds_rect, 4) ; bottom
SetError(0)
Return $RetVal
EndFunc ;==>_GetDeskWorkArea
Func GradientFill($im, $x1, $y1, $width, $height, $left_color, $right_color)
$color0 = ($left_color[0] - $right_color[0]) / $height
$color1 = ($left_color[1] - $right_color[1]) / $height
$color2 = ($left_color[2] - $right_color[2]) / $height
For $y = 0 To $height
$red = $left_color[0] - Floor($y * $color0)
$green = $left_color[1] - Floor($y * $color1)
$blue = $left_color[2] - Floor($y * $color2) ;Convert RGB to decimal
$col = Dec(Hex($red, 2) & Hex($green, 2) & Hex($blue, 2))
GUICtrlSetGraphic($im, $GUI_GR_COLOR, $col)
GUICtrlSetGraphic($im, $GUI_GR_MOVE, 0, $y)
GUICtrlSetGraphic($im, $GUI_GR_LINE, $width, $y)
Next
EndFunc ;==>GradientFill
; =================================================================================================
Wäre dankbar für jegliche Art von Feedback.
Bekannte "Fehler":
-Hohe CPU-Auslastung während dem Ein-und Ausblenden