unit Unit5;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls;
type
TForm5 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch;
var URL: OleVariant);
private
{ Private-Deklarationen }
Fcomplete:Boolean;
public
{ Public-Deklarationen }
end;
var
Form5: TForm5;
implementation
{$R *.dfm}
procedure WebBrowserPrint(
const AWebBrowser : TWebBrowser; PrinterDialog : Boolean = true);
var
vaIn, vaOut: OleVariant;
begin
if PrinterDialog
then
AWebBrowser.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_PROMPTUSER, vaIn, vaOut)
else
AWebBrowser.ControlInterface.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER, vaIn, vaOut);
end;
procedure TForm5.Button1Click(Sender: TObject);
Const
C_TIMEOUT=10000;
var
wb:TWebBrowser;
tc:Cardinal;
begin
FComplete := false;
wb:=TWebBrowser.Create(self);
try
wb.Left := -5000;
wb.ParentWindow := self.Handle;
wb.OnDocumentComplete := WebBrowser1DocumentComplete;
wb.Navigate('
C:\temp\Browser.html');
tc := GetTickCount;
while not FComplete
and ((GetTickCount - tc) < C_TIMEOUT)
do
begin
Application.ProcessMessages;
end;
finally
wb.Free;
end;
end;
procedure TForm5.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch;
var URL: OleVariant);
begin
TwebBrowser(ASender).OnDocumentComplete :=
nil;
WebBrowserPrint(TwebBrowser(ASender));
FComplete := true;
end;
end.