根据爱元元的哥哥的其他问题整理
unit UfrmUpdate;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,UrlMon, ActiveX, StdCtrls;
type
TfrmUpdate = class(TForm,IBindStatusCallback)
plStatus: TLabel;
plProgress: TLabel;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
function OnStartBinding(dwReserved: DWORD; pib: IBinding): HResult; stdcall;
function GetPriority(out nPriority): HResult; stdcall;
function OnLowResource(reserved: DWORD): HResult; stdcall;
function OnProgress(ulProgress, ulProgressMax, ulStatusCode: ULONG;szStatusText: LPCWSTR): HResult; stdcall;
function OnStopBinding(hresult: HResult; szError: LPCWSTR): HResult; stdcall;
function GetBindInfo(out grfBINDF: DWORD; var bindinfo: TBindInfo): HResult; stdcall;
function OnDataAvailable(grfBSCF: DWORD; dwSize: DWORD; formatetc: PFormatEtc;stgmed: PStgMedium): HResult; stdcall;
function OnObjectAvailable(const iid: TGUID; punk: IUnknown): HResult; stdcall;
function GetHTMLFile(URL, FileName: string): HRESULT;
public
{ Public declarations }
end;
var
frmUpdate: TfrmUpdate;
DoCancel:bool;
implementation
{$R *.dfm}
function TfrmUpdate.GetHTMLFile( URL , FileName : string) : HRESULT;
var
status : IBindStatusCallback ;
begin
status := IBindStatusCallback(self);
result := UrlDownLoadToFile(nil, pChar( URL ) ,pChar( FileName ),0 ,Status );
end;
//------------------------------------------------------------------------------
function TfrmUpdate.GetBindInfo(out grfBINDF: DWORD;
var bindinfo: TBindInfo): HResult;
begin
result := E_NOTIMPL;
end;
//------------------------------------------------------------------------------
function TfrmUpdate.GetPriority(out nPriority): HResult;
begin
result := E_NOTIMPL;
end;
//------------------------------------------------------------------------------
function TfrmUpdate.OnDataAvailable(grfBSCF, dwSize: DWORD;
formatetc: PFormatEtc; stgmed: PStgMedium): HResult;
begin
result := E_NOTIMPL;
end;
//------------------------------------------------------------------------------
function TfrmUpdate.OnLowResource(reserved: DWORD): HResult;
begin
result := E_NOTIMPL;
end;
//------------------------------------------------------------------------------
function TfrmUpdate.OnObjectAvailable(const iid: TGUID;
punk: IInterface): HResult;
begin
result := E_NOTIMPL;
end;
//------------------------------------------------------------------------------
function TfrmUpdate.OnStartBinding(dwReserved: DWORD;
pib: IBinding): HResult;
begin
result := E_NOTIMPL;
end;
//------------------------------------------------------------------------------
function TfrmUpdate.OnStopBinding(hresult: HResult;
szError: LPCWSTR): HResult;
begin
result := E_NOTIMPL;
end;
//-----------------------------------------------------------------------------
function TfrmUpdate.OnProgress(ulProgress, ulProgressMax,ulStatusCode: ULONG; szStatusText: LPCWSTR): HResult;
var
Status:string;
begin
case ulStatusCode of
BINDSTATUS_FINDINGRESOURCE : Status:='正在查找站点:' + szStatusText;
BINDSTATUS_CONNECTING : Status:='正在连接站点:' + szStatusText;
BINDSTATUS_REDIRECTING : Status:='重新定位...';
BINDSTATUS_BEGINDOWNLOADDATA : Status:='开始下载:' + szStatusText;
BINDSTATUS_DOWNLOADINGDATA : Status:='正在下载...';
BINDSTATUS_ENDDOWNLOADDATA : Status:='下载完毕:' + szStatusText;
BINDSTATUS_BEGINDOWNLOADCOMPONENTS : Status:='开始下载信息';
BINDSTATUS_INSTALLINGCOMPONENTS : Status:='开始安装信息...' ;
BINDSTATUS_ENDDOWNLOADCOMPONENTS : Status:='结束下载信息';
BINDSTATUS_USINGCACHEDCOPY : Status:='正在从缓冲区拷贝...';
BINDSTATUS_SENDINGREQUEST : Status:='正在发送请求...';
BINDSTATUS_CLASSIDAVAILABLE : Status:='CLSID 资源有效';
BINDSTATUS_MIMETYPEAVAILABLE : Status:='MIME 资源有效';
BINDSTATUS_CACHEFILENAMEAVAILABLE : Status:='缓冲区文件名可用';
BINDSTATUS_BEGINSYNCOPERATION : Status:='开始同步操作';
BINDSTATUS_ENDSYNCOPERATION : Status:='停止同步操作';
BINDSTATUS_BEGINUPLOADDATA : Status:='开始上传信息';
BINDSTATUS_UPLOADINGDATA : Status:='正在上传信息';
BINDSTATUS_ENDUPLOADDATA : Status:='停止上传信息';
BINDSTATUS_PROTOCOLCLASSID : Status:='协议可用';
BINDSTATUS_ENCODING : Status:='正在编码...';
BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE : Status:='MIME检验通过';
BINDSTATUS_CLASSINSTALLLOCATION : Status:='CLASSINSTALLLOCATION';
BINDSTATUS_DECODING : Status:='正在解码...';
BINDSTATUS_LOADINGMIMEHANDLER : Status:='LOADINGMIMEHANDLER';
BINDSTATUS_CONTENTDISPOSITIONATTACH : Status:='CONTENTDISPOSITIONATTACH';
BINDSTATUS_FILTERREPORTMIMETYPE : Status:='FILTERREPORTMIMETYPE';
BINDSTATUS_CLSIDCANINSTANTIATE : Status:='CLSIDCANINSTANTIATE';
BINDSTATUS_IUNKNOWNAVAILABLE : Status:='IUNKNOWNAVAILABLE';
BINDSTATUS_DIRECTBIND : Status:='DIRECTBIND';
BINDSTATUS_RAWMIMETYPE : Status:='MIME type of the resource, before any code sniffing is done';
BINDSTATUS_PROXYDETECTING : Status:='监测代理服务器...';
BINDSTATUS_ACCEPTRANGES : Status:='Valid types of range requests for a resource';
end;
Application.ProcessMessages;
//这个地方是你想要的!
if DoCancel then
result := E_ABORT
else
result := S_OK;
plStatus.Caption:=Status;
plProgress.Caption:='已下载:' + IntToStr(ulProgress) + '字节'+
';总共:' + IntToStr(ulProgressMax)+'字节';
end;
procedure TfrmUpdate.Button1Click(Sender: TObject);
begin
getHtmlFile('http://www.liheng.net/yasuo/ivu.exe','d:/ivu.exe');
end;
procedure TfrmUpdate.Button2Click(Sender: TObject);
begin
DoCancel:=true;
close;
end;
end.