WebBrowser控件,在浏览网页时,要下载一个文件的时候,我想弹出自己的对话框,进行下载。大家有办法吗? ( 积分: 200 )

  • 主题发起人 主题发起人 还是朋友
  • 开始时间 开始时间

还是朋友

Unregistered / Unconfirmed
GUEST, unregistred user!
要弹出自己的对话框,不要IE的那个保存文件的对话框。

只知道IE提供了一个IDownloadManager接口,要实现它。

大家帮帮忙。

unit NewWebBrowser;

interface

uses
{$IFDEF VER140}Variants,{$ENDIF} ActiveX, IEConst, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, EmbeddedWB, SHDocVw_EWB, EwbAcc, UrlMon, IEAddress,
ExtCtrls, EwbCore, SHDocVw;

type
TNewWebBrowser = class(TWebBrowser)
protected
procedure DoQueryService(const rsid, iid: TGUID; out Obj); virtual;
public
function Download(
pmk: IMoniker; // Identifies the object to be downloaded
pbc: IBindCtx; // Stores information used by the moniker to bind
dwBindVerb: DWORD; // The action to be performed during the bind
grfBINDF: DWORD; // Determines the use of URL encoding during the bind
pBindInfo: PBindInfo; // Used to implement IBindStatusCallback::GetBindInfo
pszHeaders: PWidechar; // Additional headers to use with IHttpNegotiate
pszRedir: PWidechar; // The URL that the moniker is redirected to
uiCP: UINT // The code page of the object's display name
): HRESULT; stdcall;

function QueryService(const rsid, iid: TGUID; out Obj): HRESULT; stdcall;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TNewWebBrowser]);
end;

{ TNewWebBrowser }

procedure TNewWebBrowser.DoQueryService(const rsid, iid: TGUID; out Obj);
begin
if IsEqualGuid(rsid, IID_IDownloadManager) then
IUnknown(Obj) := Self as IDownloadManager;
end;

function TNewWebBrowser.Download(pmk: IMoniker; pbc: IBindCtx; dwBindVerb,
grfBINDF: DWORD; pBindInfo: PBindInfo; pszHeaders, pszRedir: PWidechar;
uiCP: UINT): HRESULT;
begin
ShowMessage('Download');
end;

function TNewWebBrowser.QueryService(const rsid, iid: TGUID;
out Obj): HRESULT;
begin
Pointer(Obj) := nil;
DoQueryService(rsid, iid, Obj);
if Pointer(Obj) <> nil then
Result := S_OK;
end;

end.
 
后退
顶部