⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urltestmain.pas

📁 《Delphi开发人员指南》配书原码
💻 PAS
字号:
unit UrlTestMain;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ActiveX, AxCtrls, UrlTest_TLB, UrlMon, StdCtrls, MPlayer, ExtCtrls,
  ComCtrls;

type
  TUrlTestForm = class(TActiveForm, IUrlTestForm, IBindStatusCallback)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    MediaPlayer1: TMediaPlayer;
    Panel1: TPanel;
    Button1: TButton;
    StatusPanel: TPanel;
    ProgressBar1: TProgressBar;
    ServerName: TEdit;
    StaticText1: TStaticText;
    procedure Label1Click(Sender: TObject);
    procedure Label2Click(Sender: TObject);
    procedure Label3Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    FEvents: IUrlTestFormEvents;
    procedure ActivateEvent(Sender: TObject);
    procedure ClickEvent(Sender: TObject);
    procedure CreateEvent(Sender: TObject);
    procedure DblClickEvent(Sender: TObject);
    procedure DeactivateEvent(Sender: TObject);
    procedure DestroyEvent(Sender: TObject);
    procedure KeyPressEvent(Sender: TObject; var Key: Char);
    procedure PaintEvent(Sender: TObject);
  protected
    { IBindStatusCallback }
    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( hRes: HResult; szError: PWideChar ): 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;
    { UrlTestForm }
    procedure EventSinkChanged(const EventSink: IUnknown); override;
    procedure Initialize; override;
    function Get_Active: WordBool; safecall;
    function Get_AutoScroll: WordBool; safecall;
    function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
    function Get_Caption: WideString; safecall;
    function Get_Color: OLE_COLOR; safecall;
    function Get_Cursor: Smallint; safecall;
    function Get_DropTarget: WordBool; safecall;
    function Get_Enabled: WordBool; safecall;
    function Get_Font: IFontDisp; safecall;
    function Get_HelpFile: WideString; safecall;
    function Get_KeyPreview: WordBool; safecall;
    function Get_PixelsPerInch: Integer; safecall;
    function Get_PrintScale: TxPrintScale; safecall;
    function Get_Scaled: WordBool; safecall;
    function Get_Visible: WordBool; safecall;
    function Get_WindowState: TxWindowState; safecall;
    procedure Set_AutoScroll(Value: WordBool); safecall;
    procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
    procedure Set_Caption(const Value: WideString); safecall;
    procedure Set_Color(Color: OLE_COLOR); safecall;
    procedure Set_Cursor(Value: Smallint); safecall;
    procedure Set_DropTarget(Value: WordBool); safecall;
    procedure Set_Enabled(Value: WordBool); safecall;
    procedure Set_Font(const Font: IFontDisp); safecall;
    procedure Set_HelpFile(const Value: WideString); safecall;
    procedure Set_KeyPreview(Value: WordBool); safecall;
    procedure Set_PixelsPerInch(Value: Integer); safecall;
    procedure Set_PrintScale(Value: TxPrintScale); safecall;
    procedure Set_Scaled(Value: WordBool); safecall;
    procedure Set_Visible(Value: WordBool); safecall;
    procedure Set_WindowState(Value: TxWindowState); safecall;
  public
    { Public declarations }
  end;

implementation

uses ComObj, ComServ;

{$R *.DFM}

{ TUrlTestForm.IBindStatusCallback }

function TUrlTestForm.OnStartBinding(dwReserved: DWORD; pib: IBinding):
  HResult;
begin
  Result := S_OK;
end;

function TUrlTestForm.GetPriority(out nPriority): HResult;
begin
  HRESULT(Result) := S_OK;
end;

function TUrlTestForm.OnLowResource(reserved: DWORD): HResult;
begin
  Result := S_OK;
end;

function TUrlTestForm.OnProgress(ulProgress, ulProgressMax, ulStatusCode: ULONG;
  szStatusText: LPCWSTR): HResult; stdcall;
begin
  Result := S_OK;
  ProgressBar1.Max := ulProgressMax;
  ProgressBar1.Position := ulProgress;
  StatusPanel.Caption := szStatusText;
end;

function TUrlTestForm.OnStopBinding(hRes: HResult; szError: PWideChar ):
  HResult;
begin
  Result := S_OK;
  if hRes = S_OK then
  begin
    MediaPlayer1.FileName := 'c:\temp\testavi.avi';
    MediaPlayer1.Open;
    MediaPlayer1.Play;
  end;
end;

function TUrlTestForm.GetBindInfo(out grfBINDF: DWORD; var bindinfo: TBindInfo):
  HResult; stdcall;
begin
  Result := S_OK;
end;

function TUrlTestForm.OnDataAvailable(grfBSCF: DWORD; dwSize: DWORD;
  formatetc: PFormatEtc; stgmed: PStgMedium): HResult; stdcall;
begin
  Result := S_OK;
end;

function TUrlTestForm.OnObjectAvailable(const iid: TGUID; punk: IUnknown):
  HResult; stdcall;
begin
  Result := S_OK;
end;

{ TUrlTestForm }

procedure TUrlTestForm.EventSinkChanged(const EventSink: IUnknown);
begin
  FEvents := EventSink as IUrlTestFormEvents;
end;

procedure TUrlTestForm.Initialize;
begin
  OnActivate := ActivateEvent;
  OnClick := ClickEvent;
  OnCreate := CreateEvent;
  OnDblClick := DblClickEvent;
  OnDeactivate := DeactivateEvent;
  OnDestroy := DestroyEvent;
  OnKeyPress := KeyPressEvent;
  OnPaint := PaintEvent;
end;

function TUrlTestForm.Get_Active: WordBool;
begin
  Result := Active;
end;

function TUrlTestForm.Get_AutoScroll: WordBool;
begin
  Result := AutoScroll;
end;

function TUrlTestForm.Get_AxBorderStyle: TxActiveFormBorderStyle;
begin
  Result := Ord(AxBorderStyle);
end;

function TUrlTestForm.Get_Caption: WideString;
begin
  Result := WideString(Caption);
end;

function TUrlTestForm.Get_Color: OLE_COLOR;
begin
  Result := Color;
end;

function TUrlTestForm.Get_Cursor: Smallint;
begin
  Result := Smallint(Cursor);
end;

function TUrlTestForm.Get_DropTarget: WordBool;
begin
  Result := DropTarget;
end;

function TUrlTestForm.Get_Enabled: WordBool;
begin
  Result := Enabled;
end;

function TUrlTestForm.Get_Font: IFontDisp;
begin
  GetOleFont(Font, Result);
end;

function TUrlTestForm.Get_HelpFile: WideString;
begin
  Result := WideString(HelpFile);
end;

function TUrlTestForm.Get_KeyPreview: WordBool;
begin
  Result := KeyPreview;
end;

function TUrlTestForm.Get_PixelsPerInch: Integer;
begin
  Result := PixelsPerInch;
end;

function TUrlTestForm.Get_PrintScale: TxPrintScale;
begin
  Result := Ord(PrintScale);
end;

function TUrlTestForm.Get_Scaled: WordBool;
begin
  Result := Scaled;
end;

function TUrlTestForm.Get_Visible: WordBool;
begin
  Result := Visible;
end;

function TUrlTestForm.Get_WindowState: TxWindowState;
begin
  Result := Ord(WindowState);
end;

procedure TUrlTestForm.Set_AutoScroll(Value: WordBool);
begin
  AutoScroll := Value;
end;

procedure TUrlTestForm.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
begin
  AxBorderStyle := TActiveFormBorderStyle(Value);
end;

procedure TUrlTestForm.Set_Caption(const Value: WideString);
begin
  Caption := TCaption(Value);
end;

procedure TUrlTestForm.Set_Color(Color: OLE_COLOR);
begin
  Self.Color := Color;
end;

procedure TUrlTestForm.Set_Cursor(Value: Smallint);
begin
  Cursor := TCursor(Value);
end;

procedure TUrlTestForm.Set_DropTarget(Value: WordBool);
begin
  DropTarget := Value;
end;

procedure TUrlTestForm.Set_Enabled(Value: WordBool);
begin
  Enabled := Value;
end;

procedure TUrlTestForm.Set_Font(const Font: IFontDisp);
begin
  SetOleFont(Self.Font, Font);
end;

procedure TUrlTestForm.Set_HelpFile(const Value: WideString);
begin
  HelpFile := String(Value);
end;

procedure TUrlTestForm.Set_KeyPreview(Value: WordBool);
begin
  KeyPreview := Value;
end;

procedure TUrlTestForm.Set_PixelsPerInch(Value: Integer);
begin
  PixelsPerInch := Value;
end;

procedure TUrlTestForm.Set_PrintScale(Value: TxPrintScale);
begin
  PrintScale := TPrintScale(Value);
end;

procedure TUrlTestForm.Set_Scaled(Value: WordBool);
begin
  Scaled := Value;
end;

procedure TUrlTestForm.Set_Visible(Value: WordBool);
begin
  Visible := Value;
end;

procedure TUrlTestForm.Set_WindowState(Value: TxWindowState);
begin
  WindowState := TWindowState(Value);
end;

procedure TUrlTestForm.ActivateEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnActivate;
end;

procedure TUrlTestForm.ClickEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnClick;
end;

procedure TUrlTestForm.CreateEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnCreate;
end;

procedure TUrlTestForm.DblClickEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnDblClick;
end;

procedure TUrlTestForm.DeactivateEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnDeactivate;
end;

procedure TUrlTestForm.DestroyEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnDestroy;
end;

procedure TUrlTestForm.KeyPressEvent(Sender: TObject; var Key: Char);
var
  TempKey: Smallint;
begin
  TempKey := Smallint(Key);
  if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  Key := Char(TempKey);
end;

procedure TUrlTestForm.PaintEvent(Sender: TObject);
begin
  if FEvents <> nil then FEvents.OnPaint;
end;

procedure TUrlTestForm.Label1Click(Sender: TObject);
begin
  HLinkNavigateString(IUnknown(VCLComObject), 'http://www.inprise.com');
end;

procedure TUrlTestForm.Label2Click(Sender: TObject);
begin
  HLinkGoForward(IUnknown(VCLComObject));
end;

procedure TUrlTestForm.Label3Click(Sender: TObject);
begin
  HLinkGoBack(IUnknown(VCLComObject));
end;

procedure TUrlTestForm.Button1Click(Sender: TObject);
begin
  // Note: you may have to change the name of the AVI file shown in the first
  // parameter to Format to another AVI file which resides on your server.
  URLDownloadToFile(IUnknown(VCLComObject),
    PChar(Format('http://%s/Speedis.avi', [ServerName.Text])),
    'c:\temp\testavi.avi', 0, Self);
end;

initialization
  TActiveFormFactory.Create(ComServer, TActiveFormControl, TUrlTestForm,
    Class_UrlTestForm, 1, '', OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
    tmApartment);
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -