unit UBrowser1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, Menus, ExtActns, StdActns, ActnList, ImgList,
  OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    ImageList1: TImageList;
    ActionList1: TActionList;
    AOpen: TAction;
    ASaveAs: TAction;
    APrint: TAction;
    APrintPreview: TAction;
    OpenDialog1: TOpenDialog;
    ToolBar1: TToolBar;
    TBOpen: TToolButton;
    TBSave: TToolButton;
    TBPrint: TToolButton;
    TBPreview: TToolButton;
    MainMenu1: TMainMenu;
    MFile1: TMenuItem;
    MOpen1: TMenuItem;
    MSaveAs1: TMenuItem;
    N2: TMenuItem;
    MPreview1: TMenuItem;
    MPrint1: TMenuItem;
    N1: TMenuItem;
    MExit1: TMenuItem;
    procedure AOpenExecute(Sender: TObject);
    procedure ASaveAsAccept(Sender: TObject);
    procedure WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);
    procedure APrintExecute(Sender: TObject);
    procedure APrintPreviewExecute(Sender: TObject);
    procedure MExit1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses FileCtrl;
{$R *.dfm}
var SFile: AnsiString = 'Неизвестный';

procedure TForm1.AOpenExecute(Sender: TObject);
begin
 OpenDialog1.FileName := SFile;
 if (OpenDialog1.Execute)
  then begin
   // сохранение имени файла в SFile
   SFile := OpenDialog1.FileName;
   WebBrowser1.Navigate(OpenDialog1.FileName);
   Caption := 'Browser1[' + MinimizeName(SFile, Canvas, Width - 170) + ']';
  end;
end;

procedure TForm1.ASaveAsAccept(Sender: TObject);
begin
 WebBrowser1.ExecWB(OLECMDID_SAVEAS,1);
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
 ASaveAs.Enabled := (WebBrowser1.QueryStatusWB(OLECMDID_SAVEAS) and OLECMDF_ENABLED) <> 0;
 APrint.Enabled := (WebBrowser1.QueryStatusWB(OLECMDID_PRINT) and OLECMDF_ENABLED) <> 0;
 APrintPreview.Enabled := (WebBrowser1.QueryStatusWB(OLECMDID_PRINTPREVIEW) and OLECMDF_ENABLED) <> 0;
end;

procedure TForm1.APrintExecute(Sender: TObject);
begin
 WebBrowser1.ExecWB(OLECMDID_PRINT,1);
end;

procedure TForm1.APrintPreviewExecute(Sender: TObject);
begin
 WebBrowser1.ExecWB(OLECMDID_PRINTPREVIEW,1);
end;

procedure TForm1.MExit1Click(Sender: TObject);
begin
 Close;
end;

end.
