{==============================================================================

  CustomForm Control
  Copyright (C) 2000-2001 by Evgeny Kryukov
  All rights reserved

  All contents of this file and all other files included in this archive
  are Copyright (C) 2001 Evgeny Kryukov. Use and/or distribution of
  them requires acceptance of the License Agreement.

  See License.txt for licence information

===============================================================================}

unit KsWin2K;

{$I KsCommonVer.Inc}

interface

uses Windows, Classes;

const

  WS_EX_LAYERED = $00080000;

  LWA_COLORKEY  = $00000001;
  LWA_ALPHA     = $00000002;

  ULW_COLORKEY = $00000001;
  ULW_ALPHA    = $00000002;
  ULW_OPAQUE   = $00000004;

type

  PBlendFunction = ^TBlendFunction;
  _BLENDFUNCTION = record
    BlendOp: BYTE;
    BlendFlags: BYTE;
    SourceConstantAlpha: BYTE;
    AlphaFormat: BYTE;
  end;

  BLENDFUNCTION = _BLENDFUNCTION;
  LPBLENDFUNCTION = ^BLENDFUNCTION;
  TBlendFunction = _BLENDFUNCTION;

var

  SetLayeredWindowAttributes: function (hwnd: HWND; crKey: COLORREF; bAlpha: BYTE;
    dwFlags: DWORD): BOOL; stdcall;
  UpdateLayeredWindow: function (hWnd: HWND; hdcDst: HDC; pptDst: PPOINT;
    psize: PSIZE; hdcSrc: HDC; pptSrc: PPOINT; crKey: COLORREF;
    pblend: LPBLENDFUNCTION; dwFlags: DWORD): BOOL; stdcall;

function IsWin2k: boolean;

implementation {===============================================================}

const
  User32 = 'user32.dll';
  RunOnWin2K: boolean = false;
  User32Lib: Integer = 0;

procedure Initialize;
begin
  User32Lib := LoadLibrary(User32);
  if User32Lib <> 0 then
  begin
    @SetLayeredWindowAttributes := GetProcAddress(User32Lib, 'SetLayeredWindowAttributes');
    @UpdateLayeredWindow := GetProcAddress(User32Lib, 'UpdateLayeredWindow');

    if @SetLayeredWindowAttributes <> nil then
      RunOnWin2k := true;
  end;
end;

function IsWin2k: boolean;
begin
  Result := RunOnWin2K;
end;

initialization
  Initialize;
finalization
  if User32Lib <> 0 then
    FreeLibrary(User32Lib);
end.
