home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue48 / ComCorn / UrlTestMain.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1998-06-23  |  10.5 KB  |  402 lines

  1. unit UrlTestMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ActiveX, AxCtrls, UrlTest_TLB, UrlMon, StdCtrls, MPlayer, ExtCtrls,
  8.   ComCtrls;
  9.  
  10. type
  11.   TUrlTestForm = class(TActiveForm, IUrlTestForm, IBindStatusCallback)
  12.     GroupBox1: TGroupBox;
  13.     Label1: TLabel;
  14.     Label2: TLabel;
  15.     Label3: TLabel;
  16.     MediaPlayer1: TMediaPlayer;
  17.     Panel1: TPanel;
  18.     Button1: TButton;
  19.     StatusPanel: TPanel;
  20.     ProgressBar1: TProgressBar;
  21.     ServerName: TEdit;
  22.     StaticText1: TStaticText;
  23.     procedure Label1Click(Sender: TObject);
  24.     procedure Label2Click(Sender: TObject);
  25.     procedure Label3Click(Sender: TObject);
  26.     procedure Button1Click(Sender: TObject);
  27.   private
  28.     { Private declarations }
  29.     FEvents: IUrlTestFormEvents;
  30.     procedure ActivateEvent(Sender: TObject);
  31.     procedure ClickEvent(Sender: TObject);
  32.     procedure CreateEvent(Sender: TObject);
  33.     procedure DblClickEvent(Sender: TObject);
  34.     procedure DeactivateEvent(Sender: TObject);
  35.     procedure DestroyEvent(Sender: TObject);
  36.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  37.     procedure PaintEvent(Sender: TObject);
  38.   protected
  39.     { IBindStatusCallback }
  40.     function OnStartBinding(dwReserved: Longint; pib: IBinding): HResult;
  41.       stdcall;
  42.     function GetPriority(out pnPriority: Longint): HResult; stdcall;
  43.     function OnLowResource(reserved: Longint): HResult; stdcall;
  44.     function OnProgress(ulProgress: Longint; ulProgressMax: Longint;
  45.       ulStatusCode: Longint; szStatusText: PWideChar): HResult; stdcall;
  46.     function OnStopBinding( hRes: HResult; szError: PWideChar ): HResult;
  47.       stdcall;
  48.     function GetBindInfo(out grfBINDF: Longint; var pbindinfo: TBindInfo):
  49.       HResult; stdcall;
  50.     function OnDataAvailable(grfBSCF: Longint; dwSize: Longint;
  51.       var pformatetc: TFormatEtc; var pstgmed: TSTGMEDIUM): HResult; stdcall;
  52.     function OnObjectAvailable(const iid: TGUID; const punk: IUnknown):
  53.      HResult; stdcall;
  54.     { UrlTestForm }
  55.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  56.     procedure Initialize; override;
  57.     function Get_Active: WordBool; safecall;
  58.     function Get_AutoScroll: WordBool; safecall;
  59.     function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
  60.     function Get_Caption: WideString; safecall;
  61.     function Get_Color: OLE_COLOR; safecall;
  62.     function Get_Cursor: Smallint; safecall;
  63.     function Get_DropTarget: WordBool; safecall;
  64.     function Get_Enabled: WordBool; safecall;
  65.     function Get_Font: IFontDisp; safecall;
  66.     function Get_HelpFile: WideString; safecall;
  67.     function Get_KeyPreview: WordBool; safecall;
  68.     function Get_PixelsPerInch: Integer; safecall;
  69.     function Get_PrintScale: TxPrintScale; safecall;
  70.     function Get_Scaled: WordBool; safecall;
  71.     function Get_Visible: WordBool; safecall;
  72.     function Get_WindowState: TxWindowState; safecall;
  73.     procedure Set_AutoScroll(Value: WordBool); safecall;
  74.     procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
  75.     procedure Set_Caption(const Value: WideString); safecall;
  76.     procedure Set_Color(Color: OLE_COLOR); safecall;
  77.     procedure Set_Cursor(Value: Smallint); safecall;
  78.     procedure Set_DropTarget(Value: WordBool); safecall;
  79.     procedure Set_Enabled(Value: WordBool); safecall;
  80.     procedure Set_Font(const Font: IFontDisp); safecall;
  81.     procedure Set_HelpFile(const Value: WideString); safecall;
  82.     procedure Set_KeyPreview(Value: WordBool); safecall;
  83.     procedure Set_PixelsPerInch(Value: Integer); safecall;
  84.     procedure Set_PrintScale(Value: TxPrintScale); safecall;
  85.     procedure Set_Scaled(Value: WordBool); safecall;
  86.     procedure Set_Visible(Value: WordBool); safecall;
  87.     procedure Set_WindowState(Value: TxWindowState); safecall;
  88.   public
  89.     { Public declarations }
  90.   end;
  91.  
  92. implementation
  93.  
  94. uses ComObj, ComServ;
  95.  
  96. {$R *.DFM}
  97.  
  98. { TUrlTestForm.IBindStatusCallback }
  99.  
  100. function TUrlTestForm.OnStartBinding(dwReserved: Longint; pib: IBinding):
  101.   HResult;
  102. begin
  103.   Result := S_OK;
  104. end;
  105.  
  106. function TUrlTestForm.GetPriority(out pnPriority: Longint): HResult;
  107. begin
  108.   Result := S_OK;
  109. end;
  110.  
  111. function TUrlTestForm.OnLowResource(reserved: Longint): HResult;
  112. begin
  113.   Result := S_OK;
  114. end;
  115.  
  116. function TUrlTestForm.OnProgress(ulProgress: Longint; ulProgressMax: Longint;
  117.   ulStatusCode: Longint; szStatusText: PWideChar): HResult;
  118. begin
  119.   Result := S_OK;
  120.   ProgressBar1.Max := ulProgressMax;
  121.   ProgressBar1.Position := ulProgress;
  122.   StatusPanel.Caption := szStatusText;
  123. end;
  124.  
  125. function TUrlTestForm.OnStopBinding(hRes: HResult; szError: PWideChar ):
  126.   HResult;
  127. begin
  128.   Result := S_OK;
  129.   if hRes = S_OK then
  130.   begin
  131.     MediaPlayer1.FileName := 'c:\temp\testavi.avi';
  132.     MediaPlayer1.Open;
  133.     MediaPlayer1.Play;
  134.   end;
  135. end;
  136.  
  137. function TUrlTestForm.GetBindInfo(out grfBINDF: Longint;
  138.   var pbindinfo: TBindInfo): HResult;
  139. begin
  140.   Result := S_OK;
  141. end;
  142.  
  143. function TUrlTestForm.OnDataAvailable(grfBSCF: Longint; dwSize: Longint;
  144.   var pformatetc: TFormatEtc; var pstgmed: TSTGMEDIUM): HResult;
  145. begin
  146.   Result := S_OK;
  147. end;
  148.  
  149. function TUrlTestForm.OnObjectAvailable(const iid: TGUID;
  150.   const punk: IUnknown): HResult;
  151. begin
  152.   Result := S_OK;
  153. end;
  154.  
  155. { TUrlTestForm }
  156.  
  157. procedure TUrlTestForm.EventSinkChanged(const EventSink: IUnknown);
  158. begin
  159.   FEvents := EventSink as IUrlTestFormEvents;
  160. end;
  161.  
  162. procedure TUrlTestForm.Initialize;
  163. begin
  164.   OnActivate := ActivateEvent;
  165.   OnClick := ClickEvent;
  166.   OnCreate := CreateEvent;
  167.   OnDblClick := DblClickEvent;
  168.   OnDeactivate := DeactivateEvent;
  169.   OnDestroy := DestroyEvent;
  170.   OnKeyPress := KeyPressEvent;
  171.   OnPaint := PaintEvent;
  172. end;
  173.  
  174. function TUrlTestForm.Get_Active: WordBool;
  175. begin
  176.   Result := Active;
  177. end;
  178.  
  179. function TUrlTestForm.Get_AutoScroll: WordBool;
  180. begin
  181.   Result := AutoScroll;
  182. end;
  183.  
  184. function TUrlTestForm.Get_AxBorderStyle: TxActiveFormBorderStyle;
  185. begin
  186.   Result := Ord(AxBorderStyle);
  187. end;
  188.  
  189. function TUrlTestForm.Get_Caption: WideString;
  190. begin
  191.   Result := WideString(Caption);
  192. end;
  193.  
  194. function TUrlTestForm.Get_Color: OLE_COLOR;
  195. begin
  196.   Result := Color;
  197. end;
  198.  
  199. function TUrlTestForm.Get_Cursor: Smallint;
  200. begin
  201.   Result := Smallint(Cursor);
  202. end;
  203.  
  204. function TUrlTestForm.Get_DropTarget: WordBool;
  205. begin
  206.   Result := DropTarget;
  207. end;
  208.  
  209. function TUrlTestForm.Get_Enabled: WordBool;
  210. begin
  211.   Result := Enabled;
  212. end;
  213.  
  214. function TUrlTestForm.Get_Font: IFontDisp;
  215. begin
  216.   GetOleFont(Font, Result);
  217. end;
  218.  
  219. function TUrlTestForm.Get_HelpFile: WideString;
  220. begin
  221.   Result := WideString(HelpFile);
  222. end;
  223.  
  224. function TUrlTestForm.Get_KeyPreview: WordBool;
  225. begin
  226.   Result := KeyPreview;
  227. end;
  228.  
  229. function TUrlTestForm.Get_PixelsPerInch: Integer;
  230. begin
  231.   Result := PixelsPerInch;
  232. end;
  233.  
  234. function TUrlTestForm.Get_PrintScale: TxPrintScale;
  235. begin
  236.   Result := Ord(PrintScale);
  237. end;
  238.  
  239. function TUrlTestForm.Get_Scaled: WordBool;
  240. begin
  241.   Result := Scaled;
  242. end;
  243.  
  244. function TUrlTestForm.Get_Visible: WordBool;
  245. begin
  246.   Result := Visible;
  247. end;
  248.  
  249. function TUrlTestForm.Get_WindowState: TxWindowState;
  250. begin
  251.   Result := Ord(WindowState);
  252. end;
  253.  
  254. procedure TUrlTestForm.Set_AutoScroll(Value: WordBool);
  255. begin
  256.   AutoScroll := Value;
  257. end;
  258.  
  259. procedure TUrlTestForm.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
  260. begin
  261.   AxBorderStyle := TActiveFormBorderStyle(Value);
  262. end;
  263.  
  264. procedure TUrlTestForm.Set_Caption(const Value: WideString);
  265. begin
  266.   Caption := TCaption(Value);
  267. end;
  268.  
  269. procedure TUrlTestForm.Set_Color(Color: OLE_COLOR);
  270. begin
  271.   Self.Color := Color;
  272. end;
  273.  
  274. procedure TUrlTestForm.Set_Cursor(Value: Smallint);
  275. begin
  276.   Cursor := TCursor(Value);
  277. end;
  278.  
  279. procedure TUrlTestForm.Set_DropTarget(Value: WordBool);
  280. begin
  281.   DropTarget := Value;
  282. end;
  283.  
  284. procedure TUrlTestForm.Set_Enabled(Value: WordBool);
  285. begin
  286.   Enabled := Value;
  287. end;
  288.  
  289. procedure TUrlTestForm.Set_Font(const Font: IFontDisp);
  290. begin
  291.   SetOleFont(Self.Font, Font);
  292. end;
  293.  
  294. procedure TUrlTestForm.Set_HelpFile(const Value: WideString);
  295. begin
  296.   HelpFile := String(Value);
  297. end;
  298.  
  299. procedure TUrlTestForm.Set_KeyPreview(Value: WordBool);
  300. begin
  301.   KeyPreview := Value;
  302. end;
  303.  
  304. procedure TUrlTestForm.Set_PixelsPerInch(Value: Integer);
  305. begin
  306.   PixelsPerInch := Value;
  307. end;
  308.  
  309. procedure TUrlTestForm.Set_PrintScale(Value: TxPrintScale);
  310. begin
  311.   PrintScale := TPrintScale(Value);
  312. end;
  313.  
  314. procedure TUrlTestForm.Set_Scaled(Value: WordBool);
  315. begin
  316.   Scaled := Value;
  317. end;
  318.  
  319. procedure TUrlTestForm.Set_Visible(Value: WordBool);
  320. begin
  321.   Visible := Value;
  322. end;
  323.  
  324. procedure TUrlTestForm.Set_WindowState(Value: TxWindowState);
  325. begin
  326.   WindowState := TWindowState(Value);
  327. end;
  328.  
  329. procedure TUrlTestForm.ActivateEvent(Sender: TObject);
  330. begin
  331.   if FEvents <> nil then FEvents.OnActivate;
  332. end;
  333.  
  334. procedure TUrlTestForm.ClickEvent(Sender: TObject);
  335. begin
  336.   if FEvents <> nil then FEvents.OnClick;
  337. end;
  338.  
  339. procedure TUrlTestForm.CreateEvent(Sender: TObject);
  340. begin
  341.   if FEvents <> nil then FEvents.OnCreate;
  342. end;
  343.  
  344. procedure TUrlTestForm.DblClickEvent(Sender: TObject);
  345. begin
  346.   if FEvents <> nil then FEvents.OnDblClick;
  347. end;
  348.  
  349. procedure TUrlTestForm.DeactivateEvent(Sender: TObject);
  350. begin
  351.   if FEvents <> nil then FEvents.OnDeactivate;
  352. end;
  353.  
  354. procedure TUrlTestForm.DestroyEvent(Sender: TObject);
  355. begin
  356.   if FEvents <> nil then FEvents.OnDestroy;
  357. end;
  358.  
  359. procedure TUrlTestForm.KeyPressEvent(Sender: TObject; var Key: Char);
  360. var
  361.   TempKey: Smallint;
  362. begin
  363.   TempKey := Smallint(Key);
  364.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  365.   Key := Char(TempKey);
  366. end;
  367.  
  368. procedure TUrlTestForm.PaintEvent(Sender: TObject);
  369. begin
  370.   if FEvents <> nil then FEvents.OnPaint;
  371. end;
  372.  
  373. procedure TUrlTestForm.Label1Click(Sender: TObject);
  374. begin
  375.   HLinkNavigateString(IUnknown(VCLComObject), 'http://www.inprise.com');
  376. end;
  377.  
  378. procedure TUrlTestForm.Label2Click(Sender: TObject);
  379. begin
  380.   HLinkGoForward(IUnknown(VCLComObject));
  381. end;
  382.  
  383. procedure TUrlTestForm.Label3Click(Sender: TObject);
  384. begin
  385.   HLinkGoBack(IUnknown(VCLComObject));
  386. end;
  387.  
  388. procedure TUrlTestForm.Button1Click(Sender: TObject);
  389. begin
  390.   // Note: you may have to change the name of the AVI file shown in the first
  391.   // parameter to Format to another AVI file which resides on your server.
  392.   URLDownloadToFile(IUnknown(VCLComObject),
  393.     PChar(Format('http://%s/delphi3.avi', [ServerName.Text])),
  394.     'c:\temp\testavi.avi', 0, Self);
  395. end;
  396.  
  397. initialization
  398.   TActiveFormFactory.Create(ComServer, TActiveFormControl, TUrlTestForm,
  399.     Class_UrlTestForm, 1, '', OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
  400.     tmApartment);
  401. end.
  402.