HAL9000 Posted January 5, 2009 Share Posted January 5, 2009 (edited) func func _download($_url,$_name, $_left,$_top,$_width, $_height ) $_Progress = GUICtrlCreateProgress($_left,$_top,$_width, $_height ) $_size =InetGetSize ( $_url ) InetGet($_url, $_name, 1, 1) While @InetGetActive GUICtrlSetData ($_progress,Ceiling((@InetGetBytesRead/$_size)*100)) Wend endfunc example #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Dim $_left,$_top,$_width, $_height,$_Progress,$_size,$_name $gui = GUICreate("Download & Show Progress",250,60,-1,-1,$WS_POPUPWINDOW+$WS_MINIMIZEBOX) GUISetBkColor ("0x1ad1c1") winsettrans("Download & Show Progress","",200) GUISetState(@SW_SHOW) _download("http://dl3.antivir-pe.de/upd/vdf/antivir3.vdf.gz","antivir3.vdf.gz",25,20,200,20) _download("http://dl3.antivir-pe.de/upd/vdf/antivir2.vdf.gz","antivir2.vdf.gz",25,20,200,20) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd func _download($_url,$_name, $_left,$_top,$_width, $_height ) $_Progress = GUICtrlCreateProgress($_left,$_top,$_width, $_height ) $_size =InetGetSize ( $_url ) InetGet($_url, $_name, 1, 1) While @InetGetActive GUICtrlSetData ($_progress,Ceiling((@InetGetBytesRead/$_size)*100)) Wend endfunc Edited January 5, 2009 by HAL9000 Link to comment Share on other sites More sharing options...
damian666 Posted January 5, 2009 Share Posted January 5, 2009 nice code, but i thought it needed some other stuff, this will set the progress to a progress bar you specify in the function call. that way you can use a existing progressbar in a GUI ^^ let me know what ya think : Damian666 expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> Dim $_left,$_top,$_width, $_height,$_Progress,$_size,$_name Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("New Example", 294, 71, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Progress1 = GUICtrlCreateProgress(8, 8, 275, 20) $Button1 = GUICtrlCreateButton("Download", 117, 42, 75, 20, 0) GUICtrlSetOnEvent(-1, "Button1Click") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Button1Click() download("http://dl3.antivir-pe.de/upd/vdf/antivir3.vdf.gz", "antivir3.vdf.gz", $Progress1) download("http://dl3.antivir-pe.de/upd/vdf/antivir2.vdf.gz", "antivir2.vdf.gz", $Progress1) EndFunc Func Form1Close() Exit EndFunc func download($url, $target, $progress) $size =InetGetSize($url) InetGet($url, $target, 1, 1) While @InetGetActive GUICtrlSetData($progress,Ceiling((@InetGetBytesRead/$size)*100)) Wend endfunc and proud of it!!! Link to comment Share on other sites More sharing options...
MartiniThePilot Posted November 26, 2009 Share Posted November 26, 2009 (edited) nice code, but i thought it needed some other stuff, this will set the progress to a progress bar you specify in the function call. that way you can use a existing progressbar in a GUI ^^ let me know what ya think : Damian666 Thanks damian666! Like (and used) that! A small code change is required if using AutoIt version 3.3.1.x (or above) because macros @InetGetActive and @InetGetBytesRead are no longer supported. New function InetGetInfo() is to be used (but than, code REQUIRES AutoIt version 3.3.1.x (or above). For migrated code (Func download) see below. Also removed the DIM because that variables are not used. ;Migrated code for AutoIt version 3.3.1.x (and above) #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("New Example", 294, 71, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") $Progress1 = GUICtrlCreateProgress(8, 8, 275, 20) $Button1 = GUICtrlCreateButton("Download", 117, 42, 75, 20, 0) GUICtrlSetOnEvent(-1, "Button1Click") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func Button1Click() download("http://dl3.antivir-pe.de/upd/vdf/antivir3.vdf.gz", "antivir3.vdf.gz", $Progress1) download("http://dl3.antivir-pe.de/upd/vdf/antivir2.vdf.gz", "antivir2.vdf.gz", $Progress1) EndFunc Func Form1Close() Exit EndFunc func download($url, $target, $progress) $size =InetGetSize($url) $hDownload = InetGet($url, $target, 1, 1) ;1 = Forces a reload from the remote site, 1 = Return immediately and download in the background While Not InetGetInfo($hDownload, 2) ;2 = Set to True if the download is complete, False if the download is still ongoing. GUICtrlSetData($progress,Ceiling((InetGetInfo($hDownload, 0)/$size)*100)) ;0 = Bytes read so far (this is updated while the download progresses). Wend endfunc Ciao, Martini Edit: Typos. Edited November 30, 2009 by MartiniThePilot Link to comment Share on other sites More sharing options...
sheeva Posted November 26, 2009 Share Posted November 26, 2009 Hi, Just a question. Is that possible with _InetGetSource ? Thanks. Link to comment Share on other sites More sharing options...
MartiniThePilot Posted November 30, 2009 Share Posted November 30, 2009 (edited) Hi, Just a question. Is that possible with _InetGetSource ? Thanks. No. _INetGetSource() out of the Inet.au3 UDF uses InetRead() "under the hood", which has no handle or background parm/option (see (beta) help files also): ; #FUNCTION# ==================================================================================================================== ; Name...........: _INetGetSource ; Description ...: Gets the source from an URL without writing a temp file. ; Parameters ....: $s_URL - The URL of the site. ; $bString - If True the data is returned in string format, otherwise binary format. ; Return values .: Success - The read string and sets @extended to the number of bytes returned. ; Failure - An empty string and and sets @error to non-zero. ; Author ........: Wouter van Kesteren. ; =============================================================================================================================== Func _INetGetSource($s_URL, $bString = True) Local $sString = InetRead($s_URL, 1) Local $nError = @error, $nExtended = @extended If $bString Then $sString = BinaryToString($sString) Return SetError($nError, $nExtended, $sString) EndFunc ;==>_INetGetSource You may "roll your own" if you can effort the temp file: Use the code with progress bar shown in the previous posts and specify a local file name of your choice. After download has finished use FileOpen(), FileRead() and FileClose() to get the temp file into your string. If the file download lasts long enough to be worth to have a progress bar, you probably also could effort to go via a temp file. Ciao, Martini Edit: Typos. Edited November 30, 2009 by MartiniThePilot Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now