unit Unit8;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, ComCtrls, StdCtrls, Buttons, ExtCtrls,shellapi,
  jpeg;

type
  TForm8 = class(TForm)
    Image1: TImage;
    SpeedButton1: TSpeedButton;
    test5: TSpeedButton;
    StatusBar1: TStatusBar;
    GroupBox1: TGroupBox;
    TreeView1: TTreeView;
    ImageList1: TImageList;
    Label1: TLabel;
    SpeedButton3: TSpeedButton;
    GroupBox2: TGroupBox;
    Image2: TImage;
    Memo2: TMemo;
    procedure SpeedButton1Click(Sender: TObject);
    procedure test5Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure TreeView1DblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure StatusBar1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form8: TForm8;
   sPath:String[60];
  path,path1: string;
  TreeNode: TTreeNode;
  glav:boolean;
  i:integer;
implementation

uses Unit6, Unit4, Unit3, Unit5, Unit2, Unit9, Unit1;

{$R *.dfm}

procedure TForm8.SpeedButton1Click(Sender: TObject);
begin
form6.Visible :=true;
form6.Tag:=2;
end;

procedure TForm8.test5Click(Sender: TObject);
begin
 if form8.Visible then
  begin
  form8.Visible:=false;
  form4.Tag:=4;
  end
  else
  begin
   form9.Visible:=false;
   form4.Tag:=5;
  end;
 form8.Visible:=false;
 form4.SpeedButton20.Caption :='Тесті аяќтау';
 form4.Label1.Caption:='20 ден';
 //form4.DBText1.Left :=150;
 form4.Label1.Left:=80;
 form4.visible:=true;
end;

procedure TForm8.SpeedButton2Click(Sender: TObject);
begin
close;
end;

procedure TForm8.TreeView1DblClick(Sender: TObject);
var ddd:string;
   p2: array[0..100] of Char;
begin
  glav:=false;
  treenode:=treeview1.Selected;
  if treenode.level<>0 then
   begin
    treenode:=treenode.Parent;
    glav:=true;
   end;
  path1:=treenode.Text;
  if  glav=false then
    begin
      path:=spath+'\web_kz\'+path1+'.htm';
      form9.WebBrowser1.Navigate(ExpandUNCFileName(path));
      datamodule5.ADOTable2.Edit;
      datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString:=treeview1.Selected.Text;
      datamodule5.ADOTable2.Post;
      statusbar1.Panels[2].Text:=datamodule5.DataSource2.DataSet.fieldbyname('user').AsString;
      statusbar1.Panels[4].Text:=datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString;
      form9.visible:=true;
      form8.Visible:=false;
    end
  else
   begin
    if path1<>'Видео' then
      begin
        path:=spath+'\web_kz\'+path1+'.htm'+'#a'+inttostr(treeview1.Selected.Index+1);
        i:=treeview1.Selected.Index+1;
        form9.WebBrowser1.Navigate(ExpandUNCFileName(path));
        datamodule5.ADOTable2.Edit;
        datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString:=treeview1.Selected.Text;
        datamodule5.ADOTable2.Post;
        statusbar1.Panels[2].Text:=datamodule5.DataSource2.DataSet.fieldbyname('user').AsString;
        statusbar1.Panels[4].Text:=datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString;
        form9.visible:=true;
        form8.Visible:=false;
      end
    else
      begin
        path:=spath+'\video\'+inttostr(treeview1.Selected.Index+1) +'.avi';
        StrPcopy(p2, path);
        ShellExecute(Handle, nil, p2, nil, nil, SW_SHOW);
      end;
   end;
end;
procedure TForm8.FormCreate(Sender: TObject);
var   MyJPG: TJPEGImage;
begin
  GetDir(0,sPath);
  MaskBmp := TBitmap.Create;
  MyJPG := TJPEGImage.Create;
  MyJPG.LoadFromStream(TResourceStream.CreateFromID(HInstance, 2, RT_RCDATA));
  image1.Picture.Assign(MyJPG);
  try
    MaskBmp.LoadFromResourceName(HInstance, 'DW1');
    Height := MaskBmp.Height;
    Width := MaskBmp.Width;
    SetWindowRgn(Self.Handle, BitmapToRgn(MaskBmp), True);
  finally
    MaskBmp.Free;
  end;
end;
function BitmapToRgn(Image: TBitmap): HRGN;
var
  TmpRgn: HRGN;
  x, y: integer;
  ConsecutivePixels: integer;
  CurrentPixel: TColor;
  CreatedRgns: integer;
  CurrentColor: TColor;
begin
  CreatedRgns := 0;
  Result := CreateRectRgn(0, 0, maskbmp.Width, maskbmp.Height);
  inc(CreatedRgns);

  if (maskbmp.Width = 0) or (maskbmp.Height = 0) then
    exit;

  for y := 0 to maskbmp.Height - 1 do
  begin
    CurrentColor := maskbmp.Canvas.Pixels[0,y];
    ConsecutivePixels := 1;
    for x := 0 to maskbmp.Width - 1 do
    begin
      CurrentPixel := maskbmp.Canvas.Pixels[x, y];

      if CurrentColor = CurrentPixel then
        inc(ConsecutivePixels)
      else
      begin
        if CurrentColor = clWhite then
        begin
          TmpRgn := CreateRectRgn(x - ConsecutivePixels, y, x, y + 1);
          CombineRgn(Result, Result, TmpRgn, RGN_DIFF);
          inc(CreatedRgns);
          DeleteObject(TmpRgn);
        end;
        CurrentColor := CurrentPixel;
        ConsecutivePixels := 1;
      end;
    end;

    if (CurrentColor = clWhite) and (ConsecutivePixels > 0) then
    begin
      TmpRgn := CreateRectRgn(x-ConsecutivePixels, y, x, y+1);
      CombineRgn(Result, Result, TmpRgn, RGN_DIFF);
      inc(CreatedRgns);
      DeleteObject(TmpRgn);
    end;
  end;
end;


procedure TForm8.StatusBar1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
statusbar1.Hint:=statusbar1.Panels.Items[2].Text+' - '+statusbar1.Panels.Items[4].Text
end;

procedure TForm8.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const
  SC_DragMove = $F012;
begin
  ReleaseCapture;
  form8.perform(WM_SysCommand, SC_DragMove, 0);
end;
procedure TForm8.FormClose(Sender: TObject; var Action: TCloseAction);
begin
form1.close;
end;

end.
