TDownloadStatusCallback = class(TObject,IUnknown,IBindStatusCallback)
private
fUserCancel: Boolean;
function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall;
function _AddRef: Integer; stdcall;
function _Release: Integer; stdcall;
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;
public
OnFindingSource: TNotifyEvent;
OnConnecting: TNotifyEvent;
OnBeginDownload: TNotifyEvent;
OnDownLoading: TNotifyEvent;
OnEndDownLoad: TNotifyEvent;
constructor Create;
procedure CancelDownload;
end;
function TDownloadStatusCallback._AddRef: Integer;
begin
Result := 0;
end;
function TDownloadStatusCallback._Release: Integer;
begin
Result := 0;
end;
function TDownloadStatusCallback.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
if(GetInterface(IID,Obj)) then
begin
Result := 0
end
else
begin
Result := E_NOINTERFACE;
end;
end;
function TDownloadStatusCallback.OnStartBinding(dwReserved: DWORD; pib: IBinding): HResult;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.GetPriority(out nPriority): HResult;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.OnLowResource(reserved: DWORD): HResult;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.OnStopBinding(hresult: HResult; szError: LPCWSTR): HResult; stdcall;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.GetBindInfo(out grfBINDF: DWORD; var bindinfo: TBindInfo): HResult; stdcall;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.OnDataAvailable(grfBSCF: DWORD; dwSize: DWORD; formatetc: PFormatEtc; stgmed: PStgMedium): HResult;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.OnObjectAvailable(const iid: TGUID; punk: IUnknown): HResult; stdcall;
begin
Result := S_OK;
end;
function TDownloadStatusCallback.OnProgress(ulProgress, ulProgressMax,
ulStatusCode: ULONG; szStatusText: LPCWSTR): HResult;
begin
case ulStatusCode of
BINDSTATUS_FINDINGRESOURCE:
begin
if Assigned(OnFindingSource) then
OnFindingSource(Self);
if (fUserCancel) then
begin
Result := E_ABORT;
exit;
end;
end;
BINDSTATUS_CONNECTING:
begin
if Assigned(OnConnecting) then
OnConnecting(Self);
if (fUserCancel) then begin
Result := E_ABORT;
exit;
end;
end;
BINDSTATUS_BEGINDOWNLOADDATA:
begin
if Assigned(OnBeginDownload) then
OnBeginDownload(Self);
if (fUserCancel) then begin
Result := E_ABORT;
exit;
end;
end;
BINDSTATUS_DOWNLOADINGDATA:
begin
if Assigned(OnDownLoading) then
OnDownLoading(Self);
if (fUserCancel) then begin
Result := E_ABORT;
exit;
end;
end;
BINDSTATUS_ENDDOWNLOADDATA:
begin
if Assigned(OnEndDownLoad) then
OnEndDownLoad(Self);
end;
end;
Result := S_OK;
end;
constructor TDownloadStatusCallback.Create;
begin
inherited;
fUserCancel := False;
end;
-
T'ва - за StatusCallBack-a .....
-------------
Special killer double trouble triple extra nicotine monster!Редактирано от z_free на 04.10.03 13:30.