unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormDblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
type
    TAlphaTable=Array[0..255] of Byte;
    TRGBAData=Array[0..3] of Byte;
    PRGBAData=^TRGBAData;
var b1,b2,BA:TBitmap;
    BF:TBlendFunction;
    FBmpSize:TSize;
    FBmpTopLeft:TPoint;
    AlphaTable:TAlphaTable;
    pAlphaTable:Array[0..255] of TAlphaTable;
    Lb1,Lb2,LBA:Integer;
    PRGBA,PRGB:PRGBAData;
    PA:PByte;
    A:Byte;
    i,j:integer;
begin
 for i:=0 to 255 do
  for j:=0 to 255 do pAlphaTable[i,j]:=(j*i) shr 8;
  
 BorderStyle:=bsNone;
 Position:=poScreenCenter;
 b1:=TBitmap.Create;
 b2:=TBitmap.Create;
 b1.PixelFormat:=pf32Bit;
 b2.PixelFormat:=pf32Bit;
 b1.Width:=form1.Width;
 b1.Height:=form1.Height;
 b2.Width:=form1.Width;
 b2.Height:=form1.Height;
 b1.Canvas.Brush.Color:=0;
 b1.Canvas.FillRect(Rect(0,0,form1.Width,form1.Height));
 b1.Canvas.Brush.Color:=$ffffff;
 b1.Canvas.RoundRect(10,10,form1.Width-10,form1.Height-10,50,50);
 b2.Canvas.Brush.Color:=$40f0ff;
 b2.Canvas.RoundRect(10,10,form1.Width-10,form1.Height-10,50,50);
 b2.Canvas.Brush.Color:=0;
 b2.Canvas.RoundRect(50,50,form1.Width-50,form1.Height-50,10,10);
 b2.PixelFormat:=pf8Bit;
 SetWindowLong(form1.Handle, GWL_EXSTYLE, GetWindowLong(form1.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
 BF.BlendOp:=AC_SRC_OVER;
 BF.BlendFlags:=0;
 BF.SourceConstantAlpha:=255;
 BF.AlphaFormat:=AC_SRC_ALPHA;
 FBmpSize.cx := form1.Width;
 FBmpSize.cy := form1.Height;
 FBmpTopLeft := Point(0, 0);
 BA:=TBitmap.Create;
 BA.PixelFormat:=pf32Bit;
 BA.Width:=form1.Width;
 BA.Height:=form1.Height;
 LBA:=DWord(BA.Scanline[1])-DWord(BA.Scanline[0])-(form1.Width shl 2);
 Lb1:=DWord(b1.Scanline[1])-DWord(b1.Scanline[0])-(form1.Width shl 2);
 Lb2:=DWord(b2.Scanline[1])-DWord(b2.Scanline[0])-form1.Width;
 PRGBA:=BA.Scanline[0];
 PRGB:=b1.Scanline[0];
 PA:=b2.Scanline[0];
 for i:=0 to form1.Height-1 do
  begin
   for j:=0 to form1.Width-1 do
    begin
     A:=not PA^;
     AlphaTable:=pAlphaTable[A];
     PRGBA[0]:=AlphaTable[PRGB[0]];
     PRGBA[1]:=AlphaTable[PRGB[1]];
     PRGBA[2]:=AlphaTable[PRGB[2]];
     PRGBA[3]:=A;
     DWord(PRGBA):=DWord(PRGBA)+4;
     DWord(PRGB):=DWord(PRGB)+4;
     DWord(PA):=DWord(PA)+1;
    end;
    DWord(PRGBA):=DWord(PRGBA)+LBA;
    DWord(PRGB):=DWord(PRGB)+Lb1;
    DWord(PA):=DWord(PA)+Lb2;
  end;
 UpdateLayeredWindow(Handle, 0, nil, @FBmpSize, BA.Canvas.Handle, @FBmpTopLeft, clNone, @BF, ULW_ALPHA);
 BA.Free;
 b1.Free;
 b2.Free;
end;

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

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture();
  SendMessage(Handle,WM_NCLBUTTONDOWN, HTCAPTION, 0);
end;

end.
