Newsgroup: it.comp.lang.delphi
Titolo: Form trasparente

Ciao, ringrazio fin d'ora chi mi vorrà essere d'aiuto.
Ho un'esigenza un po' particolare. Esiste un componente o qualcosa del
genere che mi permetta di costruire una form trasparente. Spiego: devo
visualizzare un'immagine che in traspaenza deve far intravedere cosa c'è
sotto. Grazie mille ancora alla buonanima che dedicherà un po' del suo
tempo a questa cosa.

 genere che mi permetta di costruire una form trasparente.
io ho visto l'oggetto TStainedGlass, è carino anche se un po' lento.
non ricordo dove lo scricato, cmq delphi super page o torry penso,
cerca nella sezione form enanched o simile...
Ciao
Alan Solo

you wrote:

TStainedGlass e' su
 
www.torry.ru
--
Andrea Laforgia (
andrea_...@bigfoot.com
)
---------------------------------------------
#exclude <windows.h>

 sotto.
Questo però te lo devi smazzare da solo :-)
Ciao
Gianni


Se lavori sotto win2000 puoi usare questa utilissima unit:
{*************************************************************************
  File:    Win2k.Pas
  Version: 1.0.0
  Author:  Jamie Frater
  E.Mail:  
ja...@frater.com
 or 
jfr...@globe.net.nz
  Web:     
http://www.frater.com
  IRC:     WraithX or Wrayth at EFNet
  Date:    17 October 1999
  Delphi:  2, 3, 4, 5
  BCB:     ???
  License: Don't redistribute for cash.  Don't change and
           redistribute under your name.  Let me know
           if you fix anything or improve anything and
           I will add it to the main release with credits.
  Desc:    This unit contains a series of defines and methods
           from winuser.h for Windows 2000
  Use:     I don't have time to write a help file sorry.
           You will have to figure out what each function
           does- though it is fairly obvious in most
           cases.
    In your main form create add LoadWin2k.  In the OnClose or OnDestroy use
    UnloadWin2k.  I am using this method so that you don't get export
    errors on machines which don't have Win2k.
           You can check if you are in Win2k by doing WinVer = OS_WIN2k
           Once you have loaded it, you simply do
TransparentWindow(WindowHandle, Level, Toggle);
           Toggle turns transparency on or off.  A good level to use is 192.
           GetTrans is used so you can set up a nice TrackBar with 6 levels
for the user to pick
           from for his preferred level of transparency.
           Explicit Imported methods (Don't use these unless you are 100%
sure the user
           is running Win2k.)  You should use my methods for dynamic loading
instead:
    Function SetLayeredWindowAttributes(Handle: HWND; crKey: TColor; bAlpha:
Byte; dwFlags: DWORD): Bool; stdcall;
    function SetLayeredWindowAttributes; external 'user32.dll' name
'SetLayeredWindowAttributes;
*************************************************************************}
unit Win2k;
interface
uses Windows;
function TransparentWind(const Handle: THandle; Level: Byte; Toggle:
Boolean): Boolean;
function LoadWin2k: Boolean;
function UnLoadWin2k: Boolean;
function WinVer: Integer;
function GetTrans(Int: Integer): Byte;
var
  TransLoaded: Boolean;
const
  OS_WINNT = 1; { WINDOWS NT}
  OS_WIN32 = 0; { WINDOWS 95 OR 98}
  OS_WINS = 2; { WIN32 UNDER WIN3.1}
  OS_WINNT4 = 3; { NT 4 }
  OS_WIN2k = 4; { Win2k - duh! }
implementation
var
  LayerFunc: Function(Handle: HWND; crKey: DWord; bAlpha: Byte; dwFlags:
DWORD): Bool; stdcall;
  hDLL: HWND;
const
  WS_EX_LAYERED = $00080000;
  LWA_COLORKEY = $00000001;
  LWA_ALPHA = $00000002;
  ULW_COLORKEY = $00000001;
  ULW_ALPHA = $00000002;
  ULW_OPAQUE = $00000004;
function GetTrans(Int: Integer): Byte;
begin
  case Int of
    0: result := 0;
    1: result := 40;
    2: result := 80;
    3: result := 120;
    4: result := 160;
    5: result := 200;
    6: result := 240
  else
    result := 0;
  end;
end;
function WinVer: Integer;
var
  OSVerInfo: TOSVersionInfo;
begin
  try
    OSVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
    GetVersionEx(OSVerInfo);
    result := OSVerInfo.dwMajorVersion;
    case OSVerInfo.dwPlatformID of
      VER_PLATFORM_WIN32s: Result := OS_WINS;
      VER_PLATFORM_WIN32_WINDOWS: result := OS_WIN32;
      VER_PLATFORM_WIN32_NT: begin
        case OSVerInfo.dwMajorVersion of
          1: result := OS_WINNT;
          2: result := OS_WINNT;
          3: result := OS_WINNT;
          4: result := OS_WINNT4;
          5: result := OS_WIN2k;
        end;
      end
    else
      result := OSVerInfo.dwPlatformID;
    end;
  except
    result := -1;
  end;
end;
function LoadTransDLL: Boolean;
begin
  try
    hDLL := LoadLibrary('user32.dll');
    if hDLL <> 0 then
      @LayerFunc := GetProcAddress(hDLL, 'SetLayeredWindowAttributes');
    result := true;
  except
    result := false;
  end;
end;
function LoadWin2k: Boolean;
begin
  if WinVer = OS_WIN2k then
  begin
    try
      if LoadTransDll then
      begin
        Result := True;
        TransLoaded := True;
      end
      else
      begin
        result := false;
        TransLoaded := false;
      end;
    except
      TransLoaded := false;
      result := false;
    end;
  end
  else
    result := false;
end;
function UnLoadWin2k: Boolean;
begin
  if WinVer = OS_WIN2k then
  begin
    try
      @LayerFunc := Nil;
      FreeLibrary(HDLL);
      result := true;
    except
      result := false;
    end;
  end
  else
    result := False;
end;
function TransparentWind(const Handle: THandle; Level: Byte; Toggle:
Boolean): Boolean;
var
  dwLong,
  nAlpha: DWORD;
begin
  if WinVer = OS_WIN2k then
  begin
    if Toggle = true then
    begin // turn it on
      try
        if Level < 10 then Level := 10 // anything lower is blank
        else
          if Level > 240 then Level := 240; // anything higher is blank
        dwLong := GetWindowLong(Handle, GWL_EXSTYLE);
        nAlpha := Level;
        SetWindowLong(Handle, GWL_EXSTYLE, dwLong or WS_EX_LAYERED);
        LayerFunc(Handle, RGB(0,0,0), nAlpha, LWA_ALPHA);
        result := true;
      except
        result := false;
      end;
    end
    else
    begin // turn it off
      try
        dwLong := GetWindowLong(Handle, GWL_EXSTYLE);
        SetWindowLong(Handle, GWL_EXSTYLE, dwLong and (NOT WS_EX_LAYERED));
        result := true;
      except
        result := false;
      end;
    end;
    end
  else
    result := false; // oops- this isn't win2k
end;
end.