unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, DBCtrls,db, jpeg, StdCtrls;

type
  TForm1 = class(TForm)
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton2Click(Sender: TObject);
  private
      { Private declarations }
  public
    { Public declarations }
  end;
function BitmapToRgn(Image: TBitmap): HRGN;
var
  Form1: TForm1;
  sPath:String[60];
  MaskBmp: TBitmap;
implementation

uses Unit2, Unit5, Unit3, Unit8;

{$R *.dfm}
{$R BMP.RES}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 datamodule5.adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+spath+'\Base\test.mdb;Mode=ReadWrite;Persist Security Info=False';
 //'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+spath+'\Base\test.mdb;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Database Password=122333';
 datamodule5.ADOTable1.TableName:='test';
 datamodule5.ADOTable1.Active:=true;
 datamodule5.ADOTable2.Active:=true;
form2.statusbar1.Panels[2].Text:=datamodule5.DataSource2.DataSet.fieldbyname('user').AsString;
form2.statusbar1.Panels[4].Text:=datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString;
form1.Visible:=false;
form2.visible:=true;
end;

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

procedure TForm1.FormCreate(Sender: TObject);
var   MyJPG: TJPEGImage;
begin
  GetDir(0,sPath);
//  MaskBmp := TBitmap.Create;
//  MyJPG := TJPEGImage.Create;
//  MyJPG.LoadFromStream(TResourceStream.CreateFromID(HInstance, 1, RT_RCDATA));
//  image1.Picture.Assign(MyJPG);
//  try
//   MaskBmp.LoadFromResourceName(HInstance, 'DW');
//    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 TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
const
  SC_DragMove = $F012;
begin
  ReleaseCapture;
  form1.perform(WM_SysCommand, SC_DragMove, 0);
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
 datamodule5.adoconnection1.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+spath+'\Base\test.mdb;Mode=ReadWrite;Persist Security Info=False';
 //'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+spath+'\Base\test.mdb;Mode=ReadWrite;Persist Security Info=False;Jet OLEDB:Database Password=122333';
 datamodule5.ADOTable1.TableName:='test_kz';
 datamodule5.ADOTable1.Active:=true;
 datamodule5.ADOTable2.Active:=true;
form8.statusbar1.Panels[2].Text:=datamodule5.DataSource2.DataSet.fieldbyname('user').AsString;
form8.statusbar1.Panels[4].Text:=datamodule5.DataSource2.DataSet.fieldbyname('glava').AsString;
form1.Visible:=false;
form8.visible:=true;
end;

end.
