[ Dementia @ 13.11.2009. 18:10 ] @
Code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, URLMon, StdCtrls, ComCtrls;



type
  TForm1 = class(TForm)
    Button1: TButton;
    lbl_version: TLabel;
    ProgressBar1: TProgressBar;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function DownloadFile(SourceFile, DestFile: string): Boolean; 
begin 
  try
    Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0, nil) = 0;
  except
    Result := False;
  end;
end;


procedure check;
const
  VerSourceFile = 'http://www.google.com/images/logo_sm.gif';
  DestFile = 'logo_sm.gif';
begin
  if DownloadFile(VerSourceFile, DestFile) then
  begin

  end
  else
    ShowMessage('An error occurred')
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  check;
end;

end.



Kako da uz pomoc progress bara prikazem koliko je preostalo da se preuzme fajl...
Ako moze neki primer koda?

Hvala unapred.
[ anon68680 @ 13.11.2009. 20:05 ] @
Ako pogledas help za UrlDownloadToFile() funkciju videces:

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


ovo poslednje je pointer ka callback funkciji koja se odredjuje uz pomoc IBindStatusCallback interfejsa, odnosno OnProgress funkcije istog:

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

Onda uzmes progressbar, i stavis max value da bude ovaj preuzet iz ulProgressMax, a da Position progressbar-a bude ulProgress vrednost i to je to.


Hint: Ako vec koristis gotove code ove sa torry-a pogledaj help da razjasnis kako funkcionisu :)