_DownloadWithProgress

    • Offizieller Beitrag

    Mit dieser Funktion kann man eine Datei aus dem Internet downloaden.
    Während des Downloads werden zusätzliche Informationen (Dateigröße, Downloadgeschwindigkeit, Downloadzeit und geschätzte Restzeit) angezeigt.
    Eine Progressbar mit Prozentanzeige gibt es natürlich auch noch und man kann den Download per Button abbrechen.

    Die Übergabeparameter könnt ihr den Kommentaren entnehmen.

    Edit 25.09.2014:
    - MultiLanguage-Unterstützung (deutsch und englisch). Wenn da jemand noch andere Sprachen beisteuern möchte...
    - Flackern beseitigt (die Werte werden jetzt in extra Label angezeigt. Die Beschriftung der Werte wird nicht mehr aktualisiert).
    - Die GDI+ Variante von UEZ integriert. Vielen Dank UEZ, die Progressbar sieht klasse aus! :thumbup:
    - Den manchmal auftretenden Fehler bei 100% beseitigt. $iPercent erreicht nicht unbedingt 100% wegen dem Timer.
    - Der Abbrechen-Button ist jetzt größer.

    Edit 19.09.2021:

    - Die Links im Example aktualisiert.

    - Die UDF auf die aktuelle Version von AutoIt angepasst (inzwischen gibt es _GDIPlus_LineBrushCreate).

    - Einige kleinere Anpassungen (Schriftgröße usw.)

    Hinweis: Es wird AutoIt v3.3.12.0 oder höher benötigt!


  • Sehr schöne Funktion - werde ich jetzt sicher öfters nutzen
    Eine Frage hätte ich noch (könnte ich auch testen - aber fragen ist einfacher... :P :(
    Wenn man die Funktion aus einer GUI heraus startet - beziehen sich die GUI-Funktionen dann nach dem Aufruf dieser Funktion wieder auf das äußere GUI?
    Falls nicht: Könntest du noch am Ende ein GUISwitch auf die alte GUI einbauen (so wie du es schon mit dem EventMode machst)?

  • Hallo Oscar,

    hab' vielen Dank für diese Funktion - super Sache :) . Sieht gut aus, funktionierte bei 3 eigenen Probedownloads erfolgreich und ist sehr nützlich. Falls ich es in eigenen Projekten einsetzen wöllte (die evtl. veröffentlicht werden), würde ich entsprechend eine Namensnennung durchführen oder wie soll damit verfahren werden?

    Vielen Dank für etwaige Unterstützung (Ideen, Verbesserungsvorschläge, Kritik und Zustimmung).
    Einen angenehmen Tag noch!

    UserIsGrateful 【ツ】

  • Sehr schöööööön !!!

    Lieben Gruß,
    Alina

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Geheime Information: ;)
    OuBVU5ebLhHu5QvlnAyQB4A7SzBrvWulwL7RLl2BdH5tI6sIYspeMKeXMSXl

  • Ich war so frei und den Progressbalken geändert:

    Spoiler anzeigen
    [autoit]


    #include-once
    #include <GUIConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <InetConstants.au3>
    #include <StaticConstants.au3>
    #include <WinAPIMisc.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

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

    ; #INDEX# ======================================================================
    ; Title .........: _DownloadWithProgress
    ; AutoIt Version : 3.3.12.0 oder höher
    ; Date ..........: 22.09.2014
    ; Language ......: Deutsch
    ; Description ...: Download einer Datei aus dem Internet mit Progressbar und zusätzlichen Infos
    ; Author(s) .....: Oscar (http://www.autoit.de)
    ;===============================================================================

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

    ;===============================================================================
    ; Function Name: _DownloadWithProgress($sURL[, $sDownloadDir][, $sTitle][, $iLeft][, $iTop][, $hParent])
    ; Description: Download einer Datei aus dem Internet mit Progressbar und zusätzlichen Infos
    ; Parameter(s): $sURL = die komplette URL zu der Datei
    ; $sDownloadDir = das Verzeichnis, in das die Datei heruntergeladen werden soll (muss existieren!)
    ; $sTitle = Fenstertitel
    ; $iLeft und $iTop = Position für das Fenster
    ; $hParent = Handle zum Parentfenster
    ; Requirement(s): includes (siehe oben) und AutoIt-Version v3.3.12.0 oder höher
    ; Return Value(s): im Fehlerfall wird @error gesetzt:
    ; @error = 1 -> $sURL ist ein Leerstring
    ; @error = 2 -> das Downloadverzeichnis existiert nicht
    ; @error = 3 -> der Download wurde vom Benutzer abgebrochen
    ; @error = 4 -> während des Downloads ist ein Fehler aufgetreten
    ; @error = 5 -> der Speicherplatz auf dem Datenträger reicht nicht
    ; @error = 6 -> die Dateigröße konnte nicht ermittelt werden
    ; Author(s): Oscar (http://www.autoit.de)
    ;===============================================================================
    Func _DownloadWithProgress($sURL, $sDownloadDir = @ScriptDir, $sTitle = 'AutoIt-Download-Tool', $iLeft = -1, $iTop = -1, $hParent = 0)
    If $sURL = '' Then Return SetError(1, 0, 0)
    If Not FileExists($sDownloadDir) Then Return SetError(2, 0, 0)
    _GDIPlus_Startup()
    Global Const $aDPI = _GDIPlus_GraphicsGetDPIRatio()
    If StringRight($sDownloadDir, 1) <> '\' Then $sDownloadDir &= '\'
    HttpSetUserAgent('AutoIt-Download-Tool')
    Local $iOldEventMode = Opt('GUIOnEventMode', 0)
    If Not $hParent Then TraySetState(2) ; TrayIcon verstecken, wenn kein Parent angegeben wurde
    Local $iDownloadSize = 0, $aDownloadData, $iTimer = TimerInit(), $iError = 0, $iPercent = 0, $hDownload
    Local $iDownSpeedTimer = TimerInit(), $iDownSpeed = 0, $iRestTime = 0, $iOldTime = 0
    Local $hGui = GUICreate($sTitle, 400, 240, $iLeft, $iTop, -1, BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED), $hParent);BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED) mit -1 ersetzen, wenn GUI transparent wird
    GUISetIcon('shell32.dll', 18, $hGui)
    GUISetFont(10 * $aDPI[0], 400, 0, 'Arial', $hGui, 5)
    GUISetBkColor(0xD6D6D6, $hGui)
    GUICtrlCreateGroup('', 10, 5, 380, 165)
    GUICtrlCreateLabel(StringFormat('Datei: "%s"', StringRegExpReplace($sURL, '.+\/(.+)', '$1')), 25, 22, 350, 20)
    GUICtrlSetFont(-1, 12 * $aDPI[0], 400, 0, 'Arial', 5)
    Local $idDownloadSize = GUICtrlCreateLabel('Dateigröße:', 25, 50, 350, 16)
    Local $idDownloadSpeed = GUICtrlCreateLabel('Geschwindigkeit:', 25, 70, 350, 16)
    Local $idDownloadTime = GUICtrlCreateLabel('Downloadzeit:', 25, 90, 350, 16)
    Local $idRestTime = GUICtrlCreateLabel('Restzeit (geschätzt):', 25, 110, 350, 16)
    Local $iW = 360, $iH = 24, $iBGColor = 0xFEFEFE, $hHBmp_BG, $hB, $iSleep
    Local $idProgress = GUICtrlCreatePic("", 20, 138, $iW, $iH)
    Local $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xFFE8E5D9]]
    $hHBmp_BG = _GDIPlus_StripProgressbar($iPercent, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[1][0], $aColors[1][1], '')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    Local $idCancelButton = GUICtrlCreateButton('Download abbrechen', 120, 180, 140, 25)
    Local $hStatus = _GUICtrlStatusBar_Create($hGui)
    Local $hAttentionIcon = _WinAPI_LoadShell32Icon(77)
    Local $hOkIcon = _WinAPI_LoadShell32Icon(144)
    Local $hInfoIcon = _WinAPI_LoadShell32Icon(277)
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hInfoIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Dateigröße wird ermittelt! Bitte warten...')
    GUISetState(@SW_SHOW, $hGui)
    Local $iDriveSpaceFree = DriveSpaceFree($sDownloadDir) * 2 ^ 20 ; in Bytes umrechnen
    Local $iFileSize = InetGetSize($sURL) ; wird in Bytes ausgegeben
    If Not @error Then
    If $iDriveSpaceFree > $iFileSize Then
    _GUICtrlStatusBar_SetText($hStatus, 'Datei wird heruntergeladen...')
    $iDownSpeedTimer = TimerInit()
    GUICtrlSetData($idDownloadSize, StringFormat('Dateigröße: %s / %s', _WinAPI_StrFormatByteSize($iDownloadSize), _WinAPI_StrFormatByteSize($iFileSize)))
    GUICtrlSetData($idDownloadSpeed, StringFormat('Geschwindigkeit: %s/s', $iDownSpeed))
    $hDownload = InetGet($sURL, $sDownloadDir & StringRegExpReplace($sURL, '.+\/(.+)', '$1'), 1, 1)
    $iSleep = TimerInit()
    Do
    Switch GUIGetMsg()
    Case $idCancelButton
    $iError = 3
    ExitLoop
    Case $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hAttentionIcon)
    _WinAPI_DestroyIcon($hOkIcon)
    _WinAPI_DestroyIcon($hInfoIcon)
    InetClose($hDownload)
    HttpSetUserAgent('')
    Opt('GUIOnEventMode', $iOldEventMode)
    GUIDelete($hGui)
    Return SetError(3, 0, 0)
    EndSwitch
    $aDownloadData = InetGetInfo($hDownload)
    If $aDownloadData[$INET_DOWNLOADERROR] Then
    $iError = 4
    ExitLoop
    EndIf
    $iDownloadSize = $aDownloadData[$INET_DOWNLOADREAD]
    If TimerDiff($iTimer) > 250 Then
    $iDownSpeed = _WinAPI_StrFormatByteSize($iDownloadSize / TimerDiff($iDownSpeedTimer) * 1000)
    $iTimer = TimerInit()
    $iPercent = Int(100 / $iFileSize * $iDownloadSize)
    GUICtrlSetData($idDownloadSize, StringFormat('Dateigröße:\t\t%s / %s', _WinAPI_StrFormatByteSize($iDownloadSize), _WinAPI_StrFormatByteSize($iFileSize)))
    GUICtrlSetData($idDownloadSpeed, StringFormat('Geschwindigkeit:\t%s/s', $iDownSpeed))
    GUICtrlSetData($idDownloadTime, StringFormat('Downloadzeit:\t\t%s', _WinAPI_StrFromTimeInterval(TimerDiff($iDownSpeedTimer))))
    $iRestTime = ($iFileSize - $iDownloadSize) / ($iDownloadSize / TimerDiff($iDownSpeedTimer))
    If $iRestTime <> $iOldTime Then
    $iOldTime = $iRestTime
    GUICtrlSetData($idRestTime, StringFormat('Restzeit (geschätzt):\t%s', _WinAPI_StrFromTimeInterval($iRestTime)))
    EndIf
    EndIf
    If TimerDiff($iSleep) > 50 Then
    $hHBmp_BG = _GDIPlus_StripProgressbar($iPercent, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[1][0], $aColors[1][1], $iPercent & '%')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    $iSleep = TimerInit()
    EndIf
    Until $aDownloadData[$INET_DOWNLOADCOMPLETE]
    If $iError Then
    $hHBmp_BG = _GDIPlus_StripProgressbar($iPercent, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[0][0], $aColors[0][1], $iPercent & '%')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hAttentionIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Download abgebrochen!')
    Else
    GUICtrlSetData($idDownloadSize, StringFormat('Dateigröße:\t\t%s / %s', _WinAPI_StrFormatByteSize($iDownloadSize), _WinAPI_StrFormatByteSize($iFileSize)))
    GUICtrlSetData($idDownloadSpeed, StringFormat('Geschwindigkeit:\t%s/s', $iDownSpeed))
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hOkIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Download abgeschlossen!')
    $hHBmp_BG = _GDIPlus_StripProgressbar(100, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[1][0], $aColors[1][1], '100%')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    EndIf
    InetClose($hDownload)
    Else
    $iError = 5
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hAttentionIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Fehler! Nicht genug Platz auf dem Datenträger!')
    EndIf
    Else
    $iError = 6
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hAttentionIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Fehler! Dateigröße konnte nicht ermittelt werden!')
    EndIf
    GUICtrlSetData($idCancelButton, 'Fenster schließen')
    While True
    Switch GUIGetMsg()
    Case $idCancelButton, $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hAttentionIcon)
    _WinAPI_DestroyIcon($hOkIcon)
    _WinAPI_DestroyIcon($hInfoIcon)
    HttpSetUserAgent('')
    Opt('GUIOnEventMode', $iOldEventMode)
    GUIDelete($hGui)
    _GDIPlus_Shutdown()
    Return SetError($iError, 0, 0)
    EndSwitch
    WEnd
    EndFunc ;==>_DownloadWithProgress

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

    Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0x000000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True)
    $fPerc = $fPerc < 0 ? 0 : $fPerc
    $fPerc = $fPerc > 100 ? 100 : $fPerc

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

    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui)

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

    Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY
    Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iH)
    Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Bmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12)
    Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize)

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

    _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor)
    Local Static $iX = 0
    For $iY = 0 To $iH - 1
    Switch $iDir
    Case 1
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen)
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen)
    Case Else
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen)
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen)
    EndSwitch
    Next
    Local $tPoint1 = DllStructCreate("float;float")
    Local $tPoint2 = DllStructCreate("float;float")
    DllStructSetData($tPoint1, 1, $iW / 2) ;x1
    DllStructSetData($tPoint2, 1, $iW / 2) ;x2
    Local $hLineBrush

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

    If $bFlip Then
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2)
    DllStructSetData($tPoint1, 2, $iH / 3) ;y1
    DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2
    $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0)
    $hLineBrush = $hLineBrush[6]
    _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush)
    Else
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2)
    DllStructSetData($tPoint1, 2, 0) ;y1
    DllStructSetData($tPoint2, 2, $iH / 3) ;y2
    $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0)
    $hLineBrush = $hLineBrush[6]
    _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush)
    EndIf
    $iX = Mod($iX + $iSpeed, $iWidth)

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

    Local $hTextureBrush = _GDIPlus_TextureCreate($hBmp)

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

    _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush)
    If $bFlip Then _GDIPlus_ImageRotateFlip($hBitmap, 6)
    _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4)

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

    Local $hBrush = _GDIPlus_BrushCreateSolid(0xE0000000 + $iTextColor)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 7)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)

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

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_GraphicsDispose($hCtxt_Bmp)
    _GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_BrushDispose($hLineBrush)
    If $bHBitmap Then
    Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hHBITMAP
    EndIf
    Return $hBitmap
    EndFunc ;==>_GDIPlus_StripProgressbar

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

    Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
    Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
    If @error Then Return SetError(1, @extended, 0)
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
    If @error Then Return SetError(2, @extended, 0)
    Local $iDPI = $aResult[2]
    _GDIPlus_GraphicsDispose($hGfx)
    Local $aResults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
    Return $aResults
    EndFunc ;==>_GDIPlus_GraphicsGetDPIRatio

    [/autoit]

    Nette UDF. :thumbup:

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    2 Mal editiert, zuletzt von UEZ (25. September 2014 um 09:52)

  • Klar, der Grund ist in Zeile 47 -> BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED). Einfach die BitOR durch -1 ersetzen, dann sollten die Transparenz weg sein.

    BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED) dient dazu das Flackern beim Updaten der Label zu verhindern (Double Buffering) mit dem Nebeneffekt, dass gewisse Farben transparent sind.

    Unter Win8 habe ich nicht diesen Effekt.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (25. September 2014 um 09:23)

  • Probiere es nochmals -> Post #9.

    Anscheinend ist bei dir die DPI nicht auf Standard eingestellt.

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Besser - aber noch nicht ganz perfekt ;-):
    autoit.de/wcf/attachment/24729/

    Bevor du aber weiter rumexperimentierst sollte ich erst einmal dazu sagen, dass ich (glücklicher) Nutzer von Mactype bin.
    Das ist ein grandioser alternativer Font-Renderer für Windows.
    Ich teste es später mal in dem ich ihn deaktiviere.
    Könnte ja wahrscheinlich daran liegen auch wenn ich bei anderen Programmen ein deartiges Verhalten noch nie feststellen konnte.

  • Hab bei Zippyshare eine Datei hochgeladen und den Link eingefügt z.b http://www56.zippyshare.com/d/59742818%20Setup.exe (Link ist nur ein Beispiel) hier noch mein Script:

    Spoiler anzeigen
    [autoit]

    #include-once
    #include <GUIConstantsEx.au3>
    #include <GuiStatusBar.au3>
    #include <InetConstants.au3>
    #include <StaticConstants.au3>
    #include <WinAPIMisc.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

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

    Func _DownloadWithProgress($sURL, $sDownloadDir = @ScriptDir, $sTitle = 'Downloader', $iLeft = -1, $iTop = -1, $hParent = 0)
    If $sURL = '' Then Return SetError(1, 0, 0)
    If Not FileExists($sDownloadDir) Then Return SetError(2, 0, 0)
    _GDIPlus_Startup()
    Global Const $aDPI = _GDIPlus_GraphicsGetDPIRatio()
    If StringRight($sDownloadDir, 1) <> '\' Then $sDownloadDir &= '\'
    HttpSetUserAgent('Downloader')
    Local $iOldEventMode = Opt('GUIOnEventMode', 0)
    If Not $hParent Then TraySetState(2) ; TrayIcon verstecken, wenn kein Parent angegeben wurde
    Local $iDownloadSize = 0, $aDownloadData, $iTimer = TimerInit(), $iError = 0, $iPercent = 0, $hDownload
    Local $iDownSpeedTimer = TimerInit(), $iDownSpeed = 0, $iRestTime = 0, $iOldTime = 0
    Local $hGui = GUICreate($sTitle, 400, 240, $iLeft, $iTop, -1, -1, $hParent)
    GUISetIcon('Icon.ico', $hGui)
    GUISetFont(10, 400, 0, 'Arial', $hGui, 5)
    GUISetBkColor(0x000000, $hGui) ;Schwarz Hintergrund
    GUICtrlCreateGroup('', 10, 5, 380, 165)
    GUICtrlCreateLabel(StringFormat('Datei: "%s"', StringRegExpReplace($sURL, '.+\/(.+)', '$1')), 25, 22, 350, 20)
    GUICtrlSetFont(-1, 12, 400, 0, 'Arial', 5)
    GUICtrlSetColor(-1, 0xFFFFFF) ;Rot Dateiname
    Local $idDownloadSize = GUICtrlCreateLabel('Dateigröße:', 25, 50, 350, 16)
    GUICtrlSetColor(-1, 0xFFFF00) ;Gelb Dateigröße
    Local $idDownloadSpeed = GUICtrlCreateLabel('Geschwindigkeit:', 25, 70, 350, 16)
    GUICtrlSetColor(-1, 0xFFFF00) ;Gelb Geschwindigkeit
    Local $idDownloadTime = GUICtrlCreateLabel('Downloadzeit:', 25, 90, 350, 16)
    GUICtrlSetColor(-1, 0xFFFF00) ;Gelb Downloadzeit
    Local $idRestTime = GUICtrlCreateLabel('Restzeit (geschätzt):', 25, 110, 350, 16)
    GUICtrlSetColor(-1, 0xFFFF00) ;Gelb Restzeit
    Local $iW = 360, $iH = 24, $iBGColor = 0x1E1E1E, $hHBmp_BG, $hB, $iSleep ;Prozessbar Hintergrund
    Local $idProgress = GUICtrlCreatePic("", 20, 138, $iW, $iH)
    Local $aColors[7][2] = [[0xFFEE5F5B, 0xFFF07673],[0xFFABCC04, 0xFFBBD636],[0xFF78CCEE, 0xFF93D6F1],[0xFFFFBB58, 0xFFFFC97A],[0xFFFF6677, 0xFFFF8795],[0xFF78CCEE, 0xFFFFC97A],[0xFF78CCEE, 0xFFE8E5D9]]
    $hHBmp_BG = _GDIPlus_StripProgressbar($iPercent, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[1][0], $aColors[1][1], '')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    Local $idCancelButton = GUICtrlCreateButton('Download abbrechen', 120, 180, 140, 25)
    Local $hStatus = _GUICtrlStatusBar_Create($hGui)
    Local $hAttentionIcon = _WinAPI_LoadShell32Icon(77)
    Local $hOkIcon = _WinAPI_LoadShell32Icon(144)
    Local $hInfoIcon = _WinAPI_LoadShell32Icon(277)
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hInfoIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Dateigröße wird ermittelt! Bitte warten...')
    GUISetState(@SW_SHOW, $hGui)
    Local $iDriveSpaceFree = DriveSpaceFree($sDownloadDir) * 2 ^ 20 ; in Bytes umrechnen
    Local $iFileSize = InetGetSize($sURL) ; wird in Bytes ausgegeben
    If Not @error Then
    If $iDriveSpaceFree > $iFileSize Then
    _GUICtrlStatusBar_SetText($hStatus, 'Datei wird heruntergeladen...')
    $iDownSpeedTimer = TimerInit()
    GUICtrlSetData($idDownloadSize, StringFormat('Dateigröße: %s / %s', _WinAPI_StrFormatByteSize($iDownloadSize), _WinAPI_StrFormatByteSize($iFileSize)))
    GUICtrlSetData($idDownloadSpeed, StringFormat('Geschwindigkeit: %s/s', $iDownSpeed))
    $hDownload = InetGet($sURL, $sDownloadDir & StringRegExpReplace($sURL, '.+\/(.+)', '$1'), 1, 1)
    $iSleep = TimerInit()
    Do
    Switch GUIGetMsg()
    Case $idCancelButton
    $iError = 3
    ExitLoop
    Case $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hAttentionIcon)
    _WinAPI_DestroyIcon($hOkIcon)
    _WinAPI_DestroyIcon($hInfoIcon)
    InetClose($hDownload)
    HttpSetUserAgent('')
    Opt('GUIOnEventMode', $iOldEventMode)
    GUIDelete($hGui)
    Return SetError(3, 0, 0)
    EndSwitch
    $aDownloadData = InetGetInfo($hDownload)
    If $aDownloadData[$INET_DOWNLOADERROR] Then
    $iError = 4
    ExitLoop
    EndIf
    $iDownloadSize = $aDownloadData[$INET_DOWNLOADREAD]
    If TimerDiff($iTimer) > 250 Then
    $iDownSpeed = _WinAPI_StrFormatByteSize($iDownloadSize / TimerDiff($iDownSpeedTimer) * 1000)
    $iTimer = TimerInit()
    $iPercent = Int(100 / $iFileSize * $iDownloadSize)
    GUICtrlSetData($idDownloadSize, StringFormat('Dateigröße:\t\t%s / %s', _WinAPI_StrFormatByteSize($iDownloadSize), _WinAPI_StrFormatByteSize($iFileSize)))
    GUICtrlSetData($idDownloadSpeed, StringFormat('Geschwindigkeit:\t%s/s', $iDownSpeed))
    GUICtrlSetData($idDownloadTime, StringFormat('Downloadzeit:\t\t%s', _WinAPI_StrFromTimeInterval(TimerDiff($iDownSpeedTimer))))
    $iRestTime = ($iFileSize - $iDownloadSize) / ($iDownloadSize / TimerDiff($iDownSpeedTimer))
    If $iRestTime <> $iOldTime Then
    $iOldTime = $iRestTime
    GUICtrlSetData($idRestTime, StringFormat('Restzeit (geschätzt):\t%s', _WinAPI_StrFromTimeInterval($iRestTime)))
    EndIf
    EndIf
    If TimerDiff($iSleep) > 50 Then
    $hHBmp_BG = _GDIPlus_StripProgressbar($iPercent, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[1][0], $aColors[1][1], $iPercent & '%')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    $iSleep = TimerInit()
    EndIf
    Until $aDownloadData[$INET_DOWNLOADCOMPLETE]
    If $iError Then
    $hHBmp_BG = _GDIPlus_StripProgressbar($iPercent, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[0][0], $aColors[0][1], $iPercent & '%')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hAttentionIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Download abgebrochen!')
    Else
    GUICtrlSetData($idDownloadSize, StringFormat('Dateigröße:\t\t%s / %s', _WinAPI_StrFormatByteSize($iDownloadSize), _WinAPI_StrFormatByteSize($iFileSize)))
    GUICtrlSetData($idDownloadSpeed, StringFormat('Geschwindigkeit:\t%s/s', $iDownSpeed))
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hOkIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Download abgeschlossen!')
    $hHBmp_BG = _GDIPlus_StripProgressbar(100, $iW, $iH, 0xFF000000 + $iBGColor, $aColors[1][0], $aColors[1][1], '100%')
    $hB = GUICtrlSendMsg($idProgress, 0x0172, $IMAGE_BITMAP, $hHBmp_BG)
    If $hB Then _WinAPI_DeleteObject($hB)
    _WinAPI_DeleteObject($hHBmp_BG)
    EndIf
    InetClose($hDownload)
    Else
    $iError = 5
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hAttentionIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Fehler! Nicht genug Platz auf dem Datenträger!')
    EndIf
    Else
    $iError = 6
    _GUICtrlStatusBar_SetIcon($hStatus, 0, $hAttentionIcon)
    _GUICtrlStatusBar_SetText($hStatus, 'Fehler! Dateigröße konnte nicht ermittelt werden!')
    EndIf
    GUICtrlSetData($idCancelButton, 'Fenster schließen')
    While True
    Switch GUIGetMsg()
    Case $idCancelButton, $GUI_EVENT_CLOSE
    _WinAPI_DestroyIcon($hAttentionIcon)
    _WinAPI_DestroyIcon($hOkIcon)
    _WinAPI_DestroyIcon($hInfoIcon)
    HttpSetUserAgent('')
    Opt('GUIOnEventMode', $iOldEventMode)
    GUIDelete($hGui)
    _GDIPlus_Shutdown()
    Return SetError($iError, 0, 0)
    EndSwitch
    WEnd
    EndFunc ;==>_DownloadWithProgress

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

    Func _GDIPlus_StripProgressbar($fPerc, $iW, $iH, $iBgColorGui = 0xFFF0F0F0, $iFgColor = 0xFFEE5F5B, $iBGColor = 0xFFF07673, $sText = "Loading...", $iTextColor = 0xFF0000, $iDir = -1, $iSpeed = 1, $sFont = "Arial", $bFlip = False, $bHBitmap = True)
    $fPerc = $fPerc < 0 ? 0 : $fPerc
    $fPerc = $fPerc > 100 ? 100 : $fPerc

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

    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH)
    Local Const $hCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    _GDIPlus_GraphicsClear($hCtxt, $iBgColorGui)

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

    Local $iWidth = $iH * 2, $iLen = $iWidth / 2, $iY
    Local $hBmp = _GDIPlus_BitmapCreateFromScan0($iWidth, $iH)
    Local Const $hCtxt_Bmp = _GDIPlus_ImageGetGraphicsContext($hBmp)
    _GDIPlus_GraphicsSetPixelOffsetMode($hCtxt_Bmp, $GDIP_PIXELOFFSETMODE_HIGHQUALITY)
    Local $hPen = _GDIPlus_PenCreate($iFgColor), $iPenSize = Int($iH / 12)
    Local $hPen2 = _GDIPlus_PenCreate(0x50000000, $iPenSize)

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

    _GDIPlus_GraphicsClear($hCtxt_Bmp, $iBGColor)
    Local Static $iX = 0
    For $iY = 0 To $iH - 1
    Switch $iDir
    Case 1
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY, $iY, $iX + $iY + $iLen, $iY, $hPen)
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, $iX + $iY - 2 * $iLen, $iY, $iX + $iY - 1 * $iLen, $iY, $hPen)
    Case Else
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY, $iY, -$iX + $iY + $iLen, $iY, $hPen)
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, -$iX + $iY + 2 * $iLen, $iY, -$iX + $iY + 3 * $iLen, $iY, $hPen)
    EndSwitch
    Next
    Local $tPoint1 = DllStructCreate("float;float")
    Local $tPoint2 = DllStructCreate("float;float")
    DllStructSetData($tPoint1, 1, $iW / 2) ;x1
    DllStructSetData($tPoint2, 1, $iW / 2) ;x2
    Local $hLineBrush

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

    If $bFlip Then
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, 0, $iWidth, 0, $hPen2)
    DllStructSetData($tPoint1, 2, $iH / 3) ;y1
    DllStructSetData($tPoint2, 2, $iH * 2 / 3) ;y2
    $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0x00FFFFFF, "uint", 0xB0FFFFFF, "int", 0, "int*", 0)
    $hLineBrush = $hLineBrush[6]
    _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, $iH * 2 / 3 + 1, $iW, $iH / 3, $hLineBrush)
    Else
    _GDIPlus_GraphicsDrawLine($hCtxt_Bmp, 0, $iH - $iPenSize / 2, $iWidth, $iH - $iPenSize / 2, $hPen2)
    DllStructSetData($tPoint1, 2, 0) ;y1
    DllStructSetData($tPoint2, 2, $iH / 3) ;y2
    $hLineBrush = DllCall($__g_hGDIPDll, "uint", "GdipCreateLineBrush", "struct*", $tPoint1, "struct*", $tPoint2, "uint", 0xB0FFFFFF, "uint", 0x00FFFFFF, "int", 0, "int*", 0)
    $hLineBrush = $hLineBrush[6]
    _GDIPlus_GraphicsFillRect($hCtxt_Bmp, 0, 0, $iW, $iH / 3, $hLineBrush)
    EndIf
    $iX = Mod($iX + $iSpeed, $iWidth)

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

    Local $hTextureBrush = _GDIPlus_TextureCreate($hBmp)

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

    _GDIPlus_GraphicsFillRect($hCtxt, 0, 0, $fPerc / 100 * $iW, $iH, $hTextureBrush)
    If $bFlip Then _GDIPlus_ImageRotateFlip($hBitmap, 6)
    _GDIPlus_GraphicsSetTextRenderingHint($hCtxt, 4)

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

    Local $hBrush = _GDIPlus_BrushCreateSolid(0xE0000000 + $iTextColor)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($sFont)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $iH * 3 / 7)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, $iW, $iH)
    _GDIPlus_StringFormatSetAlign($hFormat, 1)
    _GDIPlus_StringFormatSetLineAlign($hFormat, 1)
    _GDIPlus_GraphicsDrawStringEx($hCtxt, $sText, $hFont, $tLayout, $hFormat, $hBrush)

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

    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PenDispose($hPen2)
    _GDIPlus_GraphicsDispose($hCtxt)
    _GDIPlus_GraphicsDispose($hCtxt_Bmp)
    _GDIPlus_BitmapDispose($hBmp)
    _GDIPlus_BrushDispose($hTextureBrush)
    _GDIPlus_BrushDispose($hLineBrush)
    If $bHBitmap Then
    Local $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap)
    Return $hHBITMAP
    EndIf
    Return $hBitmap
    EndFunc ;==>_GDIPlus_StripProgressbar

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

    Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
    Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
    If @error Then Return SetError(1, @extended, 0)
    Local $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)
    If @error Then Return SetError(2, @extended, 0)
    Local $iDPI = $aResult[2]
    _GDIPlus_GraphicsDispose($hGfx)
    Local $aResults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
    Return $aResults
    EndFunc ;==>_GDIPlus_GraphicsGetDPIRatio

    [/autoit]