October 30, 2025, 05:21:13 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Download Progress bar

Started by Andy, January 30, 2011, 04:33:39 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andy

Hi everyone,

Just playing with downloading a file from a website, just wondered if there was a way to show a download progress bar as the file downloads.

I've seen the progressbar example but how can you detect the file size, and the progress of the download and show that in a progress bar ?

The download example was kindly posted on the forum and works great

$use "Wininet.lib"
$use "Urlmon.lib"
declare import, URLDownloadToFileA(comref pCaller,string szURL,string szFileName,_
   int dwReserved, comref lpfnCB),int
declare import, DeleteUrlCacheEntryA(string szURL)

' optional, remove the file from browser's cache
DeleteUrlCacheEntryA("http://www.google.com/intl/en_ALL/images/logo.gif";)

' then download it
if URLDownloadToFileA(0, "http://www.google.com/intl/en_ALL/images/logo.gif";, "c:\\image.gif", 0, 0)
   Messagebox 0, "download failed", ""
else
   system "c:\\image.gif"
endif

Just would like a progress bar as a file downloads, can anyone help?
I've searched the forum and unless i've missed it I cannot find a suitable example.

Thanks,
Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

Egil

Never used it myself, but the method described in the Control Pack user guide looks straight forward. (You find the guide as a choice in the IWB help menu).

Good Luck!

Egil
Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

January 30, 2011, 07:29:04 PM #2 Last Edit: January 30, 2011, 07:30:59 PM by LarryMc
Know nothing about using COM objects but I think this tells you what you need to know:
QuoteSyntax

HRESULT URLDownloadToFile(          LPUNKNOWN pCaller,
   LPCTSTR szURL,
   LPCTSTR szFileName,
   DWORD dwReserved,
   LPBINDSTATUSCALLBACK lpfnCB
);
Parameters

pCaller
Pointer to the controlling IUnknown interface of the calling Microsoft ActiveX component (if the caller is an ActiveX component). If the calling application is not an ActiveX component, this value can be set to NULL. Otherwise, the caller is a Component Object Model (COM) object that is contained in another component (such as an ActiveX control within the context of an HTML page). This parameter represents the outermost IUnknown of the calling component. The function attempts the download within the context of the ActiveX client framework and allows the caller's container to receive callbacks on the progress of the download.
szURL
Pointer to a string value containing the URL to be downloaded. Cannot be set to NULL.
szFileName
Pointer to a string value containing the name of the file to create for bits that come from the download.
dwReserved
Reserved. Must be set to 0.
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. IBindStatusCallback::OnDataAvailable is never called. Implementing IBindStatusCallback::OnProgress allows a caller to implement a user interface or other progress monitoring functionality. It also allows the download operation to be canceled by returning E_ABORT from the IBindStatusCallback::OnProgress call. This can be set to NULL.
IBindStatusCallback::OnProgress  appears to be what you are missing
QuoteIndicates the progress of the bind operation.

Syntax

HRESULT OnProgress(          ULONG ulProgress,
    ULONG ulProgressMax,
    ULONG ulStatusCode,
    LPCWSTR szStatusText
);
Parameters

ulProgress
[in] Unsigned long integer that contains the current progress of the bind operation relative to the expected maximum indicated in the ulProgressMax parameter.
ulProgressMax
[in] Unsigned long integer that contains the expected maximum value of the ulProgress parameter for the duration of calls to IBindStatusCallback::OnProgress for this bind operation. Note that this value might change across calls to this method. A value of zero means that the maximum value of ulProgress is unknown (for example, in the IMoniker::BindToStorage method when the data download size is unknown).
ulStatusCode
[in] Unsigned long integer that receives additional information regarding the progress of the bind operation. This can be any of the BINDSTATUS values.
szStatusText
[in] Address of a string value that contains the textual information indicating the current progress of the bind operation. The text reflects the BINDSTATUS value of the ulStatusCode parameter and is appropriate for display in the user interface of the client.
Return Value

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library