UDF erstellen

  • Hallo Leute

    aufgrund von name22's Idee eine UDF hier für zu machen, hab ich es mal für Lade 2 und 3 ausprobiert, jedoch bekomme ich zahlreiche WARNING's wenn ich das script ausführe und Lade2 klappt gar nicht

    Lade2:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    OnAutoItExitRegister("_Lade_Shutdown")
    $gui = GUICreate("",400,50)
    _Lade_Startup($gui,400,50,20)
    GUISetState()
    AdlibRegister("_Lade_Bewege",10)
    Do
    $msg = GUIGetMsg()
    _Lade_Zeichne()
    Until $msg = -3
    Func _Lade_Startup($hWnd,$width,$height,$durchmesser)
    Global $w = $width
    Global $h = $height
    Global $d = $durchmesser
    Global $x[16]
    Global $brush[16]
    For $i=1 To 15 Step 1
    $x[$i] = 10-(($i-1)*10)
    Next
    _GDIPlus_Startup()
    Global $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $j = 0 To 14 Step 1
    $brush[$j+1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $j * 0x11, 2) & "60CCFF")
    Next
    Global $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    Global $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Shutdown()
    For $m = 1 To 15 Step 1
    _GDIPlus_BrushDispose($brush[$m])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Bewege()
    For $n = 1 To 15 Step 1
    If $x[$n] < $w Then $x[$n] += 2
    If $x[$n] >= $w Then $x[$n] = 0
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Zeichne()
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $w, $h, $brushWeiss)
    For $o = 1 To 15 Step 1
    _GDIPlus_GraphicsFillEllipse($buffer,$x[$o],($w-$d)/2,$d,$d,$brush[$o])
    Next
    _GDIPlus_GraphicsFillRect($buffer,0,0,20,$h,$brushWeiss)
    _GDIPlus_GraphicsFillRect($buffer,$w-40,0,20,$h,$brushWeiss)
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $w, $h)
    EndFunc

    [/autoit]

    und Lade3:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>
    OnAutoItExitRegister("Lade_shutdown")
    $gui = GUICreate("GUI",100,100)
    Lade_startup($gui,100,100)
    GUISetState()
    AdlibRegister("Lade_bewege",15)
    Do
    $msg = GUIGetMsg()
    Until $msg = -3

    [/autoit] [autoit][/autoit] [autoit]

    Func Lade_bewege()
    $startangle += 2
    $angle = Mod($angle + 3, 360)
    $r = 1 + Floor($angle / 24)
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $w, $h, $brushWeiss)
    _GDIPlus_GraphicsFillPie($buffer, 0, 0, $w, $h, $startangle, $angle, $brush[$r])
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $w, $h)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Lade_startup($hWnd,$width,$height)
    Global $w = $width
    Global $h = $height
    Global $angle = 1
    Global $r = 1
    Global $startangle = 0
    Global $brush[16]
    _GDIPlus_Startup()
    Global $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $i = 0 To 14
    $brush[$i + 1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $i * 0x11, 2) & "66CCFF")
    Next
    Global $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    Global $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    Global $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($buffer, 2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Lade_shutdown()
    For $i = 1 To 15
    _GDIPlus_BrushDispose($brush[$i])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit]

    Ich hoffe ihr könnt mir ein paar Tips geben, wie ich das verbessern kann.

    Danke
    DFPWare

  • Hallo DFPWare,
    ich habe deine Lade 3 mal überarbeitet:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $w, $h, $angle, $r, $startangle, $brush[16], $brushWeiss, $graphic, $bitmap, $buffer

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("Lade_shutdown")
    $gui = GUICreate("GUI",100,100)
    Lade_startup($gui,100,100)
    GUISetState()
    AdlibRegister("Lade_bewege",15)
    Do
    $msg = GUIGetMsg()
    Until $msg = -3

    [/autoit] [autoit][/autoit] [autoit]

    Func Lade_bewege()
    $startangle += 2
    $angle = Mod($angle + 3, 360)
    $r = 1 + Floor($angle / 24)
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $w, $h, $brushWeiss)
    _GDIPlus_GraphicsFillPie($buffer, 0, 0, $w, $h, $startangle, $angle, $brush[$r])
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $w, $h)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Lade_startup($hWnd,$width,$height)
    $w = $width
    $h = $height
    $angle = 1
    $r = 1
    $startangle = 0
    _GDIPlus_Startup()
    $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $i = 0 To 14
    $brush[$i + 1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $i * 0x11, 2) & "66CCFF")
    Next
    $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($buffer, 2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Lade_shutdown()
    For $i = 1 To 15
    _GDIPlus_BrushDispose($brush[$i])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit]

    Du kannst auch mal folgendes nachlesen http://www.autoitscript.com/autoit3/udfs/UDF_Standards.htm, da siehst du wie man die Variabelnamen besser strukturieren kann. ansonsten :thumbup: tolle UDF

    mfG
    Developer30

    Edit: ich hab ganz vergessen noch was zu meiner änderung zu sagen: Also, du siehst, ich habe nur die Globals alle mal nach oben verfrachtet. Das ganze kannst du auch mit Lade 2 mal machen, dann sind alle Warnings und Errors weg, nur dass dein Fenster weiß bleibt (soweit ich das getestet hab)

    Edit 2: hier Lade 2:

    Spoiler anzeigen
    [autoit]

    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $w, $h, $d, $x[16], $brush[16], $brushWeiss, $graphic, $bitmap, $buffer

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_Lade_Shutdown")
    $gui = GUICreate("",400,50)
    _Lade_Startup($gui,400,50,20)
    GUISetState()
    AdlibRegister("_Lade_Bewege",10)
    Do
    $msg = GUIGetMsg()
    _Lade_Zeichne()
    Until $msg = -3

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Startup($hWnd,$width,$height,$durchmesser)
    $w = $width
    $h = $height
    $d = $durchmesser
    For $i=1 To 15 Step 1
    $x[$i] = 10-(($i-1)*10)
    Next
    _GDIPlus_Startup()
    $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $j = 0 To 14 Step 1
    $brush[$j+1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $j * 0x11, 2) & "60CCFF")
    Next
    $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Shutdown()
    For $m = 1 To 15 Step 1
    _GDIPlus_BrushDispose($brush[$m])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Bewege()
    For $n = 1 To 15 Step 1
    If $x[$n] < $w Then $x[$n] += 2
    If $x[$n] >= $w Then $x[$n] = 0
    Next
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _Lade_Zeichne()
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $w, $h, $brushWeiss)
    For $o = 1 To 15 Step 1
    _GDIPlus_GraphicsFillEllipse($buffer,$x[$o],($w-$d)/2,$d,$d,$brush[$o])
    Next
    _GDIPlus_GraphicsFillRect($buffer,0,0,20,$h,$brushWeiss)
    _GDIPlus_GraphicsFillRect($buffer,$w-40,0,20,$h,$brushWeiss)
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $w, $h)
    EndFunc

    [/autoit]

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."

  • ok. so wie ich das sehe liegt es eindeutig an ($w-$d)/2

    [autoit]

    _GDIPlus_GraphicsFillEllipse($buffer,$x[$o],($w-$d)/2,$d,$d,$brush[$o])

    [/autoit]


    ich hab den Wert einfach mal durch 10 ersetzt, dann hatte es geklappt.
    Ersetzte das $w durch ein $h dann funktionierts. --> ($h-$d)/2

    "Je mehr Käse, desto mehr Löcher; je mehr Löcher, desto weniger Käse. Ergo: Je mehr Käse, desto weniger Käse. 8| "
    "Programmers never die: they just GOSUB without RETURN"
    "I tried to change the world but I couldn't find the source code."

  • Hier mal eine ausführliche Variante von Lade2, wäre das okay so?

    Spoiler anzeigen
    [autoit]

    ;Lade2
    #include <GDIPlus.au3>
    Global $iW, $iH, $iD, $aX[16], $aBrush[16], $brushWeiss, $graphic, $bitmap, $buffer

    [/autoit] [autoit][/autoit] [autoit]

    ;#Beispiel Start
    OnAutoItExitRegister("_Load_Shutdown")
    $gui = GUICreate("", 400, 50)
    _Load_Startup($gui, 400, 50, 20)
    GUISetState()
    AdlibRegister("_Load_Bewege", 10)
    Do
    $msg = GUIGetMsg()
    _Load_Zeichne()
    Until $msg = -3
    ;#Beispiel Ende
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Bewege
    ; Description ...: Moves the Beam one step to the right
    ; Syntax.........: _Load_Bewege()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func _Load_Bewege()
    For $n = 1 To 15 Step 1
    If $aX[$n] < $iW Then $aX[$n] += 2
    If $aX[$n] >= $iW Then $aX[$n] = 0
    Next
    EndFunc ;==>_Load_Bewege
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Shutdown
    ; Description ...: Cleans up resources
    ; Syntax.........: _Load_Shutdown()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func _Load_Shutdown()
    For $m = 1 To 15 Step 1
    _GDIPlus_BrushDispose($aBrush[$m])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc ;==>_Load_Shutdown
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Startup
    ; Description ...: Initialises variables and GDI+ resources
    ; Syntax.........: _Load_Startup()
    ; Parameters ....: $hWnd - Handle to the window
    ; $width - Width of the window
    ; $height - Height of the window
    ; $durchmesser - Diameter of the window
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func _Load_Startup($hWnd, $width, $height, $durchmesser)
    $iW = $width
    $iH = $height
    $iD = $durchmesser
    For $i = 1 To 15 Step 1
    $aX[$i] = 10 - (($i - 1) * 10)
    Next
    _GDIPlus_Startup()
    $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $j = 0 To 14 Step 1
    $aBrush[$j + 1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $j * 0x11, 2) & "60CCFF")
    Next
    $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    EndFunc ;==>_Load_Startup
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Zeichne
    ; Description ...: Draws the Beam
    ; Syntax.........: _Load_Zeichne()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func _Load_Zeichne()
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $iW, $iH, $brushWeiss)
    For $o = 1 To 15 Step 1
    _GDIPlus_GraphicsFillEllipse($buffer, $aX[$o], ($iH - $iD) / 2, $iD, $iD, $aBrush[$o])
    Next
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, 20, $iH, $brushWeiss)
    _GDIPlus_GraphicsFillRect($buffer, $iW - 20, 0, 20, $iH, $brushWeiss)
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $iW, $iH)
    EndFunc ;==>_Load_Zeichne

    [/autoit]

    Und hier das Selbe für Lade3

    Spoiler anzeigen
    [autoit]

    ;Lade3
    #include <GDIPlus.au3>
    Global $w,$h,$angle,$r,$startangle,$brush[16],$brushWeiss,$graphic,$bitmap,$buffer
    ;#Beispiel Start
    OnAutoItExitRegister("Load_shutdown")
    $gui = GUICreate("GUI",300,300)
    Load_startup($gui,300,300)
    GUISetState()
    AdlibRegister("Load_bewege",15)
    Do
    $msg = GUIGetMsg()
    Until $msg = -3
    ;#Beispiel Ende
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Bewege
    ; Description ...: Sets the angle one step higher, sets the transparency down and draws the cake
    ; Syntax.........: _Load_Bewege()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func Load_Bewege()
    $startangle += 2
    $angle = Mod($angle + 3, 360)
    $r = 1 + Floor($angle / 24)
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $w, $h, $brushWeiss)
    _GDIPlus_GraphicsFillPie($buffer, 0, 0, $w, $h, $startangle, $angle, $brush[$r])
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $w, $h)
    EndFunc
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Startup
    ; Description ...: Initialises variables and GDI+ resources
    ; Syntax.........: _Load_Startup()
    ; Parameters ....: $hWnd - Handle to the window
    ; $width - Width of the window
    ; $height - Height of the window
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func Load_Startup($hWnd,$width,$height)
    $w = $width
    $h = $height
    $angle = 1
    $r = 1
    $startangle = 0
    _GDIPlus_Startup()
    $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $i = 0 To 14
    $brush[$i + 1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $i * 0x11, 2) & "66CCFF")
    Next
    $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($buffer, 2)
    EndFunc
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Shutdown
    ; Description ...: Cleans up resources
    ; Syntax.........: _Load_Shutdown()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func Load_Shutdown()
    For $i = 1 To 15
    _GDIPlus_BrushDispose($brush[$i])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit]
  • Ich fürchte du musst mir doch helfen ;)

    Soweit bin ich:

    Spoiler anzeigen
    [autoit]

    ;Lade3
    #include <GDIPlus.au3>
    #include <WindowsConstants.au3>
    #include <WinAPI.au3>
    Global $w,$h,$angle,$r,$startangle,$brush[16],$brushWeiss,$graphic,$bitmap,$buffer, $hWnd
    ;#Beispiel Start
    OnAutoItExitRegister("Load_shutdown")
    $gui = GUICreate("GUI",300,300,100,100,$GUI_SS_DEFAULT_GUI, $WS_EX_LAYERED)
    Load_startup($gui,300,300)
    GUISetState()
    AdlibRegister("Load_bewege",15)
    Do
    $msg = GUIGetMsg()
    Until $msg = -3
    ;#Beispiel Ende
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Bewege
    ; Description ...: Sets the angle one step higher, sets the transparency down and draws the cake
    ; Syntax.........: _Load_Bewege()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func Load_Bewege()
    $startangle += 2
    $angle = Mod($angle + 3, 360)
    $r = 1 + Floor($angle / 24)
    _GDIPlus_GraphicsFillRect($buffer, 0, 0, $w, $h, $brushWeiss)
    _GDIPlus_GraphicsFillPie($buffer, 0, 0, $w, $h, $startangle, $angle, $brush[$r])
    _GDIPlus_GraphicsDrawImageRect($graphic, $bitmap, 0, 0, $w, $h)
    _WinAPI_UpdateLayeredWindow($hWnd, ;<==HILFE!!!###########################################################
    EndFunc
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Startup
    ; Description ...: Initialises variables and GDI+ resources
    ; Syntax.........: _Load_Startup()
    ; Parameters ....: $hWnd - Handle to the window
    ; $width - Width of the window
    ; $height - Height of the window
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func Load_Startup($handle,$width,$height)
    $hWnd = $handle
    $w = $width
    $h = $height
    $angle = 1
    $r = 1
    $startangle = 0
    _GDIPlus_Startup()
    $brushWeiss = _GDIPlus_BrushCreateSolid(0xFFFFFFFF)
    For $i = 0 To 14
    $brush[$i + 1] = _GDIPlus_BrushCreateSolid("0x" & Hex(0xFF - $i * 0x11, 2) & "66CCFF")
    Next
    $graphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $bitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $graphic)
    $buffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($buffer, 2)
    EndFunc
    ; #FUNCTION# ;===============================================================================;
    ; Name...........: _Load_Shutdown
    ; Description ...: Cleans up resources
    ; Syntax.........: _Load_Shutdown()
    ; Author ........: DFPWare
    ; Example .......; Yes
    ;; ;==========================================================================================
    Func Load_Shutdown()
    For $i = 1 To 15
    _GDIPlus_BrushDispose($brush[$i])
    Next
    _GDIPlus_BrushDispose($brushWeiss)
    _GDIPlus_GraphicsDispose($graphic)
    _GDIPlus_GraphicsDispose($buffer)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_Shutdown()
    EndFunc

    [/autoit]