以下是代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, OleCtrls, SHDocVw, ComCtrls;
type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
WebBrowser1: TWebBrowser;
Panel1: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ComboBox1: TComboBox;
OpenDialog1: TOpenDialog;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure ComboBox1KeyPress(Sender: TObject; var Key: Char);
procedure WebBrowser1DownloadBegin(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
procedure WebBrowser1TitleChange(Sender: TObject;
const Text: WideString);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
procedure gotopage(geturl:string);
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure tform1.gotopage(geturl:string);
//var
//newurl1:widestring;
begin
// newurl1:=widestring(geturl);
webbrowser1.Navigate(geturl);
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if opendialog1.Execute then
gotopage(opendialog1.FileName);
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
gotopage(combobox1.Text);
end;
procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
gotopage(combobox1.Text);
end;
procedure TForm1.WebBrowser1DownloadBegin(Sender: TObject);
begin
statusbar1.Panels[0].Text:='downloading'+ webbrowser1.LocationURL+'...';
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
var
newurl:string;
begin
statusbar1.Panels[0].Text:='done';
newurl:=webbrowser1.LocationURL;
if (newurl<>'')and (combobox1.Items.IndexOf(newurl)<0) then
combobox1.Items.Add(newurl);
end;
procedure TForm1.WebBrowser1TitleChange(Sender: TObject;
const Text: WideString);
begin
caption:=text;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
gotopage(extractfilepath(application.ExeName)+'default.htm');
end;
end.