How to use the alpha transparency features included in Windows 2000 and later #96

const
  WS_EX_LAYERED = $80000;
  LWA_COLORKEY = 1;
  LWA_ALPHA = 2;


type
  TSetLayeredWindowAttributes = function(
    hwnd: HWND;    {handle to the layered window}
    crKey: TColor; {specifies the color key}
    bAlpha: byte;  {value for the blend function}
    dwFlags: DWORD {action}
  ): BOOL; stdcall;


procedure TForm1.FormCreate(Sender: TObject);
var
  Info: TOSVersionInfo;
  F: TSetLayeredWindowAttributes;
begin
  inherited;
  Info.dwOSVersionInfoSize := SizeOf(Info);
  GetVersionEx(Info);
  if (Info.dwPlatformId = VER_PLATFORM_WIN32_NT) and
    (Info.dwMajorVersion >= 5) then
  begin
    F := GetProcAddress(
      GetModulehandle(user32), 'SetLayeredWindowAttributes'
    );
    if Assigned(F) then
    begin
      SetWindowLong(
        Handle,
        GWL_EXSTYLE,
        GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_LAYERED
      );
      F(Handle, 0, Round(255 * 80 / 100), LWA_ALPHA);
    end;
  end;
end;
Original resource: The Delphi Pool
Author: Serhiy Perevoznyk
Added: 2009/09/14
Last updated: 2009/09/14