// Mit dem
folgenden Code kann man Formen samt aller Komponenten // ACHTUNG!
Die Funktion ist erst ab W2000 verfügbar!
//
Variante 1 (dynamisch)
const
LAYERED = 524288;
procedure Transparenz(h: THandle; Alpha: Byte);
var
m: Thandle;
f: function(hwnd: HWND; crKey: DWord; bAlpha: Byte;
dwFlags: Longint): Longint; stdcall;
begin
m := LoadLibrary('User32.dll');
if m <> 0 then begin
@f := GetProcAddress(m, 'SetLayeredWindowAttributes');
if @f <> nil then begin
SetWindowLong(h, GWL_EXSTYLE, GetWindowLong(h, GWL_EXSTYLE) or LAYERED);
f(h, 0, Alpha, 2);
freelibrary(m);
end;
end;
end;
procedure Normal(h: THandle);
begin
SetWindowLong(h, GWL_EXSTYLE, GetWindowLong(h, GWL_EXSTYLE)
and not LAYERED);
end;
// Tranzparenz einstellen
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Transparenz(handle, 175); // 255 = nicht transparent; 0 = total durchsichtig
end;
// Tranzparenz abschaltehn
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
Normal(handle);
end;
// ----------------------------------------------------------------- // Variante 2 (statisch) unit transp;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
function SetLayeredWindowAttributes(const hWnd: HWND; crKey: DWord;
bAlpha: Byte; dwFlags: Longint): Integer; stdcall; external 'User32.dll';
implementation
{$R *.DFM}
const
LAYERED = 524288;
procedure Transparenz(h: THandle; Alpha: Byte);
begin
SetWindowLong(h, GWL_EXSTYLE, GetWindowLong(h, GWL_EXSTYLE) or LAYERED);
SetLayeredWindowAttributes(h, 0, Alpha, 2);
end;
procedure Normal(h: THandle);
begin
SetWindowLong(h, GWL_EXSTYLE, GetWindowLong(h, GWL_EXSTYLE)
and not LAYERED);
end;
// Tranzparenz einstellen
procedure TForm1.Button1Click(Sender: TObject);
begin
Transparenz(handle, 175); // 255 = nicht transparent; 0 = total durchsichtig
end;
// Tranzparenz abschaltehn
procedure TForm1.Button2Click(Sender: TObject);
begin
Normal(handle);
end;
end.
// -----------------------------------------------------------------
//
Variante 3 für höhere Delphi-Versionen
// Hier ein Beispiel zum Einblenden eines Formulars. // Getestet mit D2010 unter W7 var first: Boolean; procedure TForm1.FormActivate(Sender: TObject);
begin
if first then
begin
first := False;
AlphaBlendValue := 0;
repeat
AlphaBlendValue := AlphaBlendValue + 17;
application.ProcessMessages;
sleep(25); // z.B.
until AlphaBlendValue > 254;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
first := True;
AlphaBlend := true;
end;
|
Zugriffe seit 6.9.2001 auf Delphi-Ecke





