AutoHotkey Community

It is currently May 25th, 2012, 6:08 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
PostPosted: May 24th, 2007, 8:57 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
This is a preliminary/oversimplified version which will show a progress percentage of downloading of a web file.
It's written on request of our dear friend SKAN.

It was become possible due to the ingenious work by JGR, callback.dll, which is absolutely needed in the script.
Many thanks to him.

PS. I used DebugView here to display the percentage.
And, please keep in mind that this is only a test version, so there may be problems. Then, please inform me.

RegisterCallback version:
Code:
sUrl  := "http://www.autohotkey.com/download/AutoHotkeyInstall.exe"
sFile := A_Temp . "\AutoHotkeyInstall.exe"

Progress, % "M W" . A_ScreenWidth//2, 0, 0 of 0
VarSetCapacity(vt, 4*11), nParam = 31132253353
Loop, Parse, nParam
   NumPut(RegisterCallback("DownloadProgress", "Fast", A_LoopField, A_Index-1), vt, 4*(A_Index-1))
DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0, "UintP", &vt)

DownloadProgress(pthis, nProgress = 0, nProgressMax = 0, nStatusCode = 0, pStatusText = 0)
{
   If A_EventInfo = 6
   Progress, % p := 100 * nProgress//nProgressMax, %p%, % nProgress . " of " . nProgressMax
   Return 0
}

callback.dll version:
Code:
sUrl  := "http://download.sysinternals.com/Files/DebugView.zip"
sFile := "C:\DebugView.zip"

DetectHiddenWindows, On
Process, Exist
hAHK := WinExist("ahk_pid " . ErrorLevel)

OnMessage(WM_AHK_Callback := DllCall("RegisterWindowMessage", "str", "WM_AHK_Callback"), "WM_AHK_Callback")

VarSetCapacity(vt, 4*11), hModule := DllCall("LoadLibrary", "str", "callback"), nParams = 31132253353
Loop, Parse, nParams
   EncodeInteger(&vt + 4*(A_Index-1), hCallback%A_Index% := DllCall("callback\callbackit", "Uint", A_LoopField, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", A_Index-1))

MsgBox, % DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0x10, "UintP", &vt) . "|" . ErrorLevel . "|" . A_LastError

Loop, 11
   DllCall("GlobalFree", "Uint", hCallback%A_Index%)
DllCall("FreeLibrary", "Uint", hModule)
ExitApp


WM_AHK_Callback(wParam, lParam)
{
   OutputDebug, % wParam <> 6 ? wParam : DecodeInteger(lParam+4)/DecodeInteger(lParam+8) * 100
   Return 0
}

DecodeInteger(ref, nSize = 4)
{
   DllCall("RtlMoveMemory", "int64P", val, "Uint", ref, "Uint", nSize)
   Return val
}

EncodeInteger(ref, val = 0, nSize = 4)
{
   DllCall("RtlMoveMemory", "Uint", ref, "int64P", val, "Uint", nSize)
}


Last edited by Sean on June 13th, 2007, 2:12 am, edited 5 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 9:13 am 
I really like to see to be surrounded by proffessionals Image.
Thx Sean & to all of you out there. Keep up your good work.
Much appreciated. Image

:D Image Have fun :D


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 9:32 am 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Dear Sean,

I expected this, but not so fast.. :o
I am overwhelmed!.. Thank you

This looks like a dream. I will reply as soon as I wake-up.

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 9:47 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Thanks, BoBo and Skan. :D
I simplified the script a little.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 10:29 am 
Offline

Joined: December 27th, 2005, 1:46 pm
Posts: 6837
Location: France (near Paris)
Aah, the power of copy/paste...
I prefer this form:
Code:
sUrl  = http://www.autohotkey.com/download/AutoHotkeyInstall.exe
sFile = C:\AutoHotkeyInstall.exe

DetectHiddenWindows, On
Process, Exist
hAHK := WinExist("ahk_pid " . ErrorLevel)
Progress M W400 R1-100, -, Downloading, %A_ScriptName%

WM_AHK_Callback := DllCall("RegisterWindowMessage", "str", "WM_AHK_Callback")
OnMessage(WM_AHK_Callback, "WM_AHK_Callback")

hModule    := DllCall("LoadLibrary", "str", "callback")
vals = 31132253353
Loop 11
{
   i := A_Index - 1
   v := SubStr(vals, A_Index, 1)
   hCallback%i% := DllCall("callback\callbackit", "Uint", v, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", i)
}

VarSetCapacity(vt, 4 *11)
Loop 11
{
   i := A_Index - 1
   EncodeInteger(&vt+ 4 * i, hCallback%i%)
}

MsgBox, % DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0x10, "UintP", &vt) . "|" . ErrorLevel "|" A_LastError

Loop 11
{
   i := A_Index - 1
   DllCall("GlobalFree", "Uint", hCallback%i%)
}
DllCall("FreeLibrary","Uint", hModule)
ExitApp


WM_AHK_Callback(wParam, lParam)
{
   p := wParam <> 6 ? wParam : DecodeInteger(lParam+4)/DecodeInteger(lParam+8) * 100
   Progress %p%, % Floor(p)
   Return 0
}
I added a progress bar, I first thought it didn't worked, as I expected to see the IE download progress bar...

_________________
Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 10:40 am 
Offline

Joined: January 31st, 2005, 9:50 am
Posts: 3910
Location: Bremen, Germany
And this a another simplified mod of a part of PhiLhos script. *Not tested* Since I do not have callback.dll installed yet
Code:
vals = 31132253353
Loop, Parse, vals
   hCallback%A_Index% := DllCall("callback\callbackit", "Uint", A_LoopField, "Uint", hAHK, "Uint", WM_AHK_Callback, "Uint", A_Index - 1)
VarSetCapacity(vt, 4 *11)
Loop 11
   EncodeInteger(&vt+ 4 * (A_Index - 1), hCallback%A_Index%)
MsgBox, % DllCall("urlmon\URLDownloadToFileA", "Uint", 0, "str", sUrl, "str", sFile, "Uint", 0x10, "UintP", &vt) . "|" . ErrorLevel "|" A_LastError
Loop 11
   DllCall("GlobalFree", "Uint", hCallback%A_Index%)

_________________
Ciao
toralf
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 11:17 am 
@PhiLho
Thanks for the working example. I have been following the "callback"
discussions here, and have not been able to get any of the examples
to work on Win98.

Your posted code (after I added XXXInteger subroutines) worked
very well :D

This forum would be alot less useful without your presence.
(and some other gurus also :) )


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 1:21 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Dear Sean, :)

I tested your code and it does not work for me in Win 2k SP4 / Win XP SP2
I get the MsgBox with ErrorLevel:0xc0000005 and LastError:126

    ---------------------------
    URL.ahk
    ---------------------------
    |0xc0000005|126
    ---------------------------
    OK
    ---------------------------


Ditto with PhiLho's code.

:roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 1:33 pm 
Offline

Joined: June 15th, 2006, 6:29 am
Posts: 59
Location: Oriel College
Put a pause command just before the DllCall, and post the contents of your variables.
Also check that you actually have the callback.dll and urlmon.dll

JGR


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 24th, 2007, 1:40 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
JGR wrote:
Check that you actually have the callback.dll


That was it! Long awaited, and glad to have this facility.
Thanks to you and Sean

:D


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 12:14 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
toralf wrote:
And this a another simplified mod of a part of PhiLhos script.

I like it. I updated the script.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2007, 1:55 pm 
Offline

Joined: May 28th, 2006, 1:00 pm
Posts: 31
I get an error on line10 :?:

Quote:
This line does not contain a recognized action.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2007, 2:20 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
AbsolutePressure wrote:
I get an error on line10 :?:

What build of AHK are you using currently?
I just noticed Chris updated AHK to 1.0.46.16 today, it can be a good time to update if you're using some older build.
And, don't forget to download callback.dll too, which is linked at the top post.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2007, 2:21 pm 
This usually means your version of AutoHotkey is too old. Sean uses some new facilities, like assignment as expression and multiple expression on one line.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: May 30th, 2007, 10:41 pm 
Offline

Joined: May 28th, 2006, 1:00 pm
Posts: 31
Yes, I looked and I am using an old version. Sorry. I have 1.0.46.10, but I will update today. I am certainly not blaming anyone but myself for the mistake, but I would like to make a forum suggestion. The suggestion would be in having the scripts labeled in the version they were created. This might help ignorant post such as mine from having the wrong version.

Sorry Sean for posting the error off my own mistake, and thanks for sharing this script.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 47 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google Feedfetcher and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group