|
-
Jul 13th, 2001, 02:43 AM
#1
Thread Starter
Fanatic Member
DownloadFile progress bar?
I've been using the DownloadFile API ( http://www.vb-world.net/internet/tip501.html ) but need to put in a progress bar or download counter for those really big files. Any ideas?
 Looking for a friendly intelligent chat forum? Visit the white-hart.net 
-
Jul 13th, 2001, 03:56 AM
#2
i kinda have one idea...
umm what u could do is grab the filesize of the file being downloaded somehow (i dont know how) and have a timer constantly check the length of the LOCALNAME file.
this is sketchy, forgive me if it dont work
Code:
dim localname as string,ttlsize as long
localname = "C:\windows\desktop\doc1.doc"
ttlsize = <dont know how to do this!>
progressbar1.max = 100
timer1.interval = 250
private sub timer1_timer()
sizesofar = filelen(localname)
progressbar1.value = (ttlsize / 100) * sizesofar
end sub
-
Jul 13th, 2001, 11:45 AM
#3
Member
I was woundering the same thing...please e-mail me ([email protected]) if anything comes up...
-
Jul 18th, 2001, 12:24 PM
#4
Junior Member
you can use the file system object in vb to get the size of the file.
Private Sub Command1_Click()
Dim fso As New FileSystemObject
Dim fil As File
Dim fils As Files
Set fil = fso.GetFile("c:\serveranalyzerresults.txt")
List1.AddItem fil.Size
End Sub
make sure you select ms scripting runtime in refferences in project menu
-
Jul 18th, 2001, 04:17 PM
#5
Thread Starter
Fanatic Member
 Looking for a friendly intelligent chat forum? Visit the white-hart.net 
-
Jul 20th, 2001, 02:44 AM
#6
And how would one go about implementing that?
-
Jul 20th, 2001, 03:07 AM
#7
Hyperactive Member
Well kids I did some diggin,
This seems to provide the answer... but I'm just not that well versed in classes and whatnot.
http://www.domaindlx.com/e_morcillo/...ip.asp?tip=adl
Does this help?
-
Jul 20th, 2001, 05:52 AM
#8
Yes it does!
I was already starting to wrote that class myself, but I didn't feel like writing a .tlb. Now I won't have to to either!
-
Jul 20th, 2001, 06:47 AM
#9
Does anyone know how to register a friggin' typelib without writing a program to do it for me?
You have REGSVR32.EXE for .dll's, but what for typelibs?
-
Jul 20th, 2001, 02:48 PM
#10
Hyperactive Member
I am still totally confused about the typelib (I know it's a type library... but what does that do?). Can any explain how this works in providing that function?
-
Jul 20th, 2001, 03:22 PM
#11
OK, I have completed a program to download some files with URLDownloadToFile with a progressbar and abort function.
Basically, the typelib allows you to say:
VB Code:
Implements IBindStatusCallBack
Then you must implement all methods of that interface, no problem, you only need to put code in one of them: IBindStatusCallBack_OnProgress(), here's how I did it.
VB Code:
Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long)
#If fDEBUG = True Then
Static id As Long
id = id + 1
Debug.Print "[" & id & "] Progress event received: " & ulProgress & " of " & ulProgressMax & ", StatusCode: " & ulStatusCode
#End If
Dim bs As Single, ks As Integer
If ulProgress = 0 Then
tStartDownload = Timer
Else
bs = ulProgress / (Timer - tStartDownload)
End If
If bs > 0 Then ks = bs \ 1024 Else ks = 0
pbrFile.Min = 0
pbrFile.Max = 100
pbrFile.Value = CInt(100 * (ulProgress / ulProgressMax))
pbrFile.ToolTipText = ulProgress & " / " & ulProgressMax & " @ " & ks & "KB/s"
DoEvents
End Sub
-
Jul 20th, 2001, 04:19 PM
#12
Hyperactive Member
Ok... thanks, I am understanding it (kinda) now. When you are through could you post your project here so I can take a look at it?
Basically I want to see where I have to put that subroutine and also do I have to put that entire typelib file in my project (what about space concerns?) or can I just put only the part I need?
-
Jul 20th, 2001, 05:19 PM
#13
Originally posted by davem
also do I have to put that entire typelib file in my project (what about space concerns?) or can I just put only the part I need? [/B]
You need to register the TypeLib, using regtlib.exe, which comes with VB. Then reference it (Project -> References).
I don't believe you need to distribute the typelib with the compiled program, but I'm not 100% sure of that. VB should just take the part it needs and compile it into your program. You should not need the .TLB file.
For an example, look at this AsyncDownload class.
-
Jul 23rd, 2001, 01:35 AM
#14
Hyperactive Member
Ok, I saw the sample code and I did the references and stuff and I have stared at that class file till I'm blue in the face. I am new to this stuff so could you guys make a simple project file that uses the DownloadFile API to get a file, and this other typelib crap to display the progress bar? This would be soooooo much appreciated!
-
Jul 23rd, 2001, 07:24 AM
#15
Here you go, as simple as I could make it. Just type a URL in the box (or leave it as-is, the file is 5MB) and click download.
Click abort to stop downloading, click quit to quit.
I didn't even add a progress bar, but instead I have a listbox that lists the progress events as they come in.
-
Jul 23rd, 2001, 12:41 PM
#16
Hyperactive Member
Great... that helped immensely.
So the Implements IBindStatusCallback means that we use the code for IBindStatusCallback that's in the typelib (which I take it is a kind of module with code in it) in our project.
See the main thing I was confused with was how the OnProgress event get's called (since it isn't called from within our program). Does the code in the typelib tell that event to run... or Windows API just sending it messages?
Anyways... thanks alot for all the help.
-
Jul 23rd, 2001, 12:56 PM
#17
Originally posted by davem
[B]Great... that helped immensely.
So the Implements IBindStatusCallback means that we use the code for IBindStatusCallback that's in the typelib (which I take it is a kind of module with code in it) in our project.
Close, but not really. The typelib doesn't contain ANY code. It merely tells anyone who wants to know that anything that Implements IBindStatusCallback has a number of functions (like OnProgress), nothing else. It only tells other programs how to use yours.
See the main thing I was confused with was how the OnProgress event get's called (since it isn't called from within our program). Does the code in the typelib tell that event to run... or Windows API just sending it messages?
Since there is no code in the typelib, windows calls our program. The typelib just tells windows WHAT part of the program to call (the OnProgresss event).
-
Jul 23rd, 2001, 01:06 PM
#18
Hyperactive Member
Finally got it! Thanks for bearing with me.
So in general a typelib is kinda (and I use this analogy very, very loosely) like a constructor (for functions).
-
Jul 23rd, 2001, 01:17 PM
#19
Originally posted by davem
So in general a typelib is kinda (and I use this analogy very, very loosely) like a constructor (for functions).
It's more like a contract. If I decide to write Inplements IBindStatusCallback in my class (form, whatever) I promise that my class or form will have all functions of that interface.
The interface itself it nothing but a piece of paper, an agreement. If I implement it, someone else will know that my program had such&such functions, because I promised it would have by implementing the interface.
It's more complicated than that, but I think this is a nice explanation.
-
Jul 23rd, 2001, 01:25 PM
#20
Hyperactive Member
That is a nice analogy. 'preciate it and take care.
PS: One last annoying question (I promise): Do you know where I can get a list of what those codes mean... like Progress event recieved, code: 32, 0 / 0?
-
Jul 23rd, 2001, 02:05 PM
#21
Originally posted by davem
That is a nice analogy. 'preciate it and take care.
PS: One last annoying question (I promise): Do you know where I can get a list of what those codes mean... like Progress event recieved, code: 32, 0 / 0?
Open the Object Browser (F2?) and pick the lib 'olelib', then find BINDSTATUS in the left list and in the right list will be a listing of all values. You can see the numeric value of a constant bij selecting it and looking in the bottom box.
-
Jul 23rd, 2001, 09:46 PM
#22
Hyperactive Member
Ok Gerco... I lied!!!
I got everything to work great (this was exactly what I wanted)... but check this post I wrote...
Here's what the post says (I wrote you about this because I think the OnProgress event is causing this behavior!)
http://forums.vb-world.net/showthrea...threadid=91353
Alright... wierd deal.
I have a public function on a form (a download progress form) that I call from another form. Now statements execute normally in that function... but if I click the close box the form unloads (I set the form = Nothing in the Form_Unload event) the statements still execute!
Windows calls an IBindStatusCallback_OnProgress event repeatedly in my program. This might be why the statements in that function keep going even after I have unloaded it!
What can I do to stop the rest of the statements in that function from executing after the form has been unloaded?
-
Jul 24th, 2001, 06:09 PM
#23
The answer is quite simple. Look at the example I gave you.
When you click the close button (the X, I mean), the VB runtime calls Form_QueryUnload, in that function, I abort the download (if there is one and unload the form. If you don't abort the download, windows will re-load your form and execute the code in the OnProgress event.
I had the same problem as you did, and this fixed it. ALWAYS! abort the current download before unloading your form, if you don't it will either be reloaded, or your program will go GPF. It's not a hard choice to make.
-
Dec 25th, 2001, 02:23 PM
#24
Hyperactive Member
to register the type library in windows98 using regtlib.exe, what file do i register? that tl_ole.msi file?
-
Dec 25th, 2001, 03:58 PM
#25
Originally posted by HAVocINCARNATE29
to register the type library in windows98 using regtlib.exe, what file do i register? that tl_ole.msi file?
the .tlb file is what you need to register. But seeing that you have .msi file (MS Windows Installer file), you just need to execute it, it will probably register itself.
If you cannot execute the file, go and download the Windows Installer redistributables at www.microsoft.com
-
Jun 7th, 2003, 12:17 PM
#26
Frenzied Member
I know this thread is like a yr and half old but...
does anyone still have the type library / class ETC which was mensioned above?
if so, could you post it / email me it please?
w_pearsall [at] yahoo [dot] co [dot] uk
Thanks
-
Aug 11th, 2003, 10:23 AM
#27
New Member
Anyone have the type library...
The link provided in the thread no longer exists...
http://www.domaindlx.com/e_morcillo...tip.asp?tip=adl
Can someone post a new link to the type library that will allow you to reference the OnProgress method from IBindStatusCallback?
The goal is to provide a progress bar while downloadinga file using URLDownloadToFile.
Last edited by dougw; Aug 11th, 2003 at 10:30 AM.
Programming today is a race between software engineers
striving to build bigger and better idiot- proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
-- Rich Cook
-
Aug 11th, 2003, 09:38 PM
#28
Frenzied Member
-
Aug 12th, 2003, 09:39 AM
#29
New Member
One last request....I have avoided using pointer in VB like the plauge...for obvious reasons.
How do you pass the pointer to the caller's IBindStatusCallback interface? I have all the methods declared blank except OnProgress where I have the progress bar stuff...
I cannot figure out how to get the reference to either IBindStatusCallback::OnProgress or just IBindStatusCallback for the last parameter in the URLDownloadToFile function.
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
lpfnCB
Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data.
Programming today is a race between software engineers
striving to build bigger and better idiot- proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
-- Rich Cook
-
Aug 12th, 2003, 11:54 AM
#30
Frenzied Member
copy the two TLB files from the zip file, then in the downloads, theirs an accual download application, just mod-out the app to what u need, its all i did with my update prog..
-
Aug 12th, 2003, 12:58 PM
#31
New Member
Humm...the zip file that I downloaded does contain the TLB files, but the samples directory within the ZIP does not have a download example.
This is the list of sample applications:
- ActiveDesktop
ComponentCategoriesMgr
Context Menu
Extents
Invoke sample
Specify Property Pages
TypeInfo sample
TypeInfo Sample 2
Programming today is a race between software engineers
striving to build bigger and better idiot- proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
-- Rich Cook
-
Aug 13th, 2003, 12:56 PM
#32
New Member
Got it working!
I am guessing that you (wpearsall) were talking about the site:
Edanmo's MVPS VB Site
I saw his AsnycDownload and worked from that...
Here is the class module that I am using along with the TLBs (olelib.tlb and olelib2.tlb)...
Code:
Option Explicit
Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
'
' Implement IBindStatusCallback to receive
' the data and progress notification
Implements IBindStatusCallback
Function download(source As String, dest As String) As Long
Dim rc As Long
rc = URLDownloadToFileW(Me, source, dest, 0, Me)
End Function
Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long)
frmDownload.ProgressBar1.Min = 0
frmDownload.ProgressBar1.Max = 100
frmDownload.ProgressBar1.Value = CInt(100 * (ulProgress / ulProgressMax))
End Sub
Sub IBindStatusCallback_GetBindInfo( _
grfBINDF As olelib.BINDF, _
pbindinfo As olelib.BINDINFO)
' Not used
End Sub
Function IBindStatusCallback_GetPriority() As Long
' Not used
End Function
Sub IBindStatusCallback_OnStartBinding( _
ByVal dwReserved As Long, _
ByVal pib As olelib.IBinding)
' Not used
End Sub
Sub IBindStatusCallback_OnDataAvailable( _
ByVal grfBSCF As olelib.BSCF, _
ByVal dwSize As Long, _
pformatetc As olelib.FORMATETC, _
pstgmed As olelib.STGMEDIUM)
' Not used
End Sub
Sub IBindStatusCallback_OnLowResource( _
ByVal reserved As Long)
' Not used
End Sub
Sub IBindStatusCallback_OnObjectAvailable( _
riid As olelib.UUID, _
ByVal punk As stdole.IUnknown)
' Not used
End Sub
Sub IBindStatusCallback_OnStopBinding( _
ByVal hresult As Long, ByVal szError As Long)
' Not used
End Sub
The form (frmDownload) contains 2 text boxes (Source URL and Destination file), a command button to call the download function from the class and the progress bar.
Programming today is a race between software engineers
striving to build bigger and better idiot- proof programs,
and the Universe trying to produce bigger and better idiots.
So far, the Universe is winning.
-- Rich Cook
-
Jun 7th, 2008, 12:40 PM
#33
New Member
Re: DownloadFile progress bar?
 Originally Posted by trjack52
Code:
HRESULT hr;
LPBINDSTATUSCALLBACK lpfnCB;
Well im stuck on this one
help me now i got a progress bar and im using an update option in my program
These varibles are on the top:
Lcc-win32/Visual Basic Code:
HRESULT hr;
LPBINDSTATUSCALLBACK lpfnCB;
im not sure if its correct
ModifyProgressBar(PROGRESSHANDLE,TEXTTODRAWINBAR,DISPLAY %,DISPLAY CUSTOM TEXT); is from my dll differnt style to the progress bar mind
still uses the same class just sends a pain message;
and:
Lcc-win32 Code:
hr = URLDownloadToFile(0,urlname,"UPDATER.INI",1,0);
if(hr==S_OK){
ModifyProgressBar(hPB,"File status ",1,1);
SendMessage(hPB, PBM_SETPOS, (WPARAM) 100, 0) ;
}else{
ModifyProgressBar(hPB,"File status ",1,1);
SendMessage(hPB, PBM_SETPOS, (WPARAM) 0, 0) ;
}
^ ok it works but i can do more
Ok insted of it going to 100% and thats it no ACTUWAL percent i need an actuwall download here
Lcc-win32 Code:
ModifyProgressBar(hPB,"File status ",1,1);
SendMessage(hPB, PBM_SETPOS, [FONT="Arial Black"][COLOR="Red"](WPARAM) 100[/COLOR][/FONT], 0) ;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|