unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, VirtualTrees, DTDBTreeView, DTADOTree, ExtCtrls, sPanel,
  OleCtrls, SHDocVw, sSplitter, MSHTML, ShellAPI, MMSystem, sSkinManager,
  StdCtrls, sButton;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    sPanel1: TsPanel;
    sPanel2: TsPanel;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    N5: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    N8: TMenuItem;
    N9: TMenuItem;
    sPanel3: TsPanel;
    DTADOTree2: TDTADOTree;
    procedure Webput(b:Byte);
    procedure FileCaption(b:Byte);
    procedure DTADOTree2Change(Sender: TBaseVirtualTree;
      Node: PVirtualNode);
    procedure DTADOTree2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure N9Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure N7Click(Sender: TObject);
    procedure N6Click(Sender: TObject);
    procedure N8Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  s:String;
  Lek:Boolean=True;
  lab:Boolean=false;
  Primer:Boolean=false;

implementation

uses Datam;

{$R *.dfm}

procedure TForm1.DTADOTree2Change(Sender: TBaseVirtualTree;
  Node: PVirtualNode);
begin
 if Lek=True then
   Webput(1)
   else
 if lab=True then
   Webput(2);
end;

procedure TForm1.DTADOTree2MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
if Lek=True then
DTADOTree2.Hint:=DataModule2.ADOQuery1.FieldValues[DTADOTree2.DBTreeFields.ListFieldName];
if Lab=True then
DTADOTree2.Hint:=DataModule2.ADOQuery2.FieldValues[DTADOTree2.DBTreeFields.ListFieldName];
end;

procedure TForm1.Webput(b:Byte);
var
lek_s:String;
lab_s:String;
begin
case b of
1 : if DataModule2.ADOQuery1.FieldByName('put').AsString<>'' then
 begin
  lek_s:=ExtractFilePath(Application.ExeName);
  WebBrowser1.Navigate(lek_s+'html\'+DataModule2.ADOQuery1.FieldValues['Put']+'.htm');
 end;
2 :  if DataModule2.ADOQuery2.FieldByName('put').AsString<>'' then
 begin
  lab_s:=ExtractFilePath(Application.ExeName);
  WebBrowser1.Navigate(lab_s+'html\'+DataModule2.ADOQuery2.FieldValues['Put']+'.htm');
 end;
end;
end;

procedure TForm1.FileCaption(b:Byte);
begin
case b of
1: with DataModule2.ADOQuery1, DTADOTree2.DBTreeFields do
 begin
  DisableControls;
  DTADOTree2.DataSource:=DataModule2.DataSource1;
  ListFieldName:='Name';
  KeyFieldName:='Key';
  ParentFieldName:='Parent';
  HasChildrenFieldName:='HasChildren';
  EnableControls;
  sPanel2.Caption:='Лекции';
  First;
  Webput(1);
  Lek:=True;
  Primer:=False;
  lab:=False;
//  Glosari:=False;
 end;

2: with DataModule2.ADOQuery2, DTADOTree2.DBTreeFields do
 begin
  DisableControls;
  DTADOTree2.DataSource:=DataModule2.DataSource2;
  ListFieldName:='Name';
  KeyFieldName:='Key';
  ParentFieldName:='Parent';
  HasChildrenFieldName:='HasChildren';
  EnableControls;
  sPanel2.Caption:='Лабораторные';
  First;
  Webput(2);
  Lek:=False;
  Primer:=False;
  lab:=True;
//  Glosari:=False;
 end;
3: with DataModule2.ADOQuery3, DTADOTree2.DBTreeFields do
 begin
  s:=ExtractFilePath(Application.ExeName);
  WebBrowser1.Navigate(s+'html\Глоссарий.htm');
  Lek:=False;
  lab:=False;
//  Glosari:=True;
 end;
4:begin
  s:=ExtractFilePath(Application.ExeName);
  WebBrowser1.Navigate(s+'html\Перечень вопросов к экзамену.htm');
end;
5:begin
  s:=ExtractFilePath(Application.ExeName);
  WebBrowser1.Navigate(s+'html\Список  литературы .htm');
end;
end;
end;
procedure TForm1.N9Click(Sender: TObject);
begin
    repeat
           Application.ProcessMessages;
     until WebBrowser1.ReadyState >= READYSTATE_COMPLETE;
     if WebBrowser1.Document <> nil then
     (Webbrowser1.Document as IHTMLDocument2).ParentWindow.Focus;
     keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), 0, 0);
     keybd_event(Ord('F'), MapVirtualKey(Ord('F'), 0), 0, 0);
     keybd_event(Ord('F'), MapVirtualKey(Ord('F'), 0), KEYEVENTF_KEYUP, 0);
     keybd_event(VK_CONTROL, MapVirtualKey(VK_CONTROL, 0), KEYEVENTF_KEYUP, 0)
end;

procedure TForm1.N2Click(Sender: TObject);
var vaIn, vaOut: OleVariant;
begin
  WebBrowser1.ControlInterface.ExecWB(OLECMDID_PRINTPREVIEW,
    OLECMDEXECOPT_PROMPTUSER, vaIn, vaOut);
end;

procedure TForm1.N3Click(Sender: TObject);
var vaIn, vaOut: OleVariant; 
begin
  WebBrowser1.ControlInterface.ExecWB(OLECMDID_PRINT,
      OLECMDEXECOPT_PROMPTUSER,vaIn, vaOut);
end;

procedure TForm1.N7Click(Sender: TObject);
begin
WebBrowser1.GoForward;
end;

procedure TForm1.N6Click(Sender: TObject);
begin
WebBrowser1.GoBack;
end;

procedure TForm1.N8Click(Sender: TObject);
begin
     WebBrowser1.Refresh;
end;

procedure TForm1.N4Click(Sender: TObject);
begin
close;
end;

end.
