Einzelnen Beitrag anzeigen

Nils_13

Registriert seit: 15. Nov 2004
2.647 Beiträge
 
#3

Re: Transparenz eines Fensters einstellen

  Alt 2. Jul 2006, 13:46
Das läuft aber nicht in allen Windows-Systemen.
Der folgende Code sollte das besser erledigen:
Delphi-Quellcode:
unit trans;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

procedure MakeTransparent(AHandle : THandle; AValue : byte = 0);

implementation

type
    TSetLayeredWindowAttributes = function (
    hwnd : HWND;
    crKey : TColor;
    bAlpha : byte;
    dwFlags : DWORD
    ): BOOL; stdcall;

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

procedure MakeTransparent(AHandle : THandle; AValue : byte = 0);
var
  Info: TOSVersionInfo;
  SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
begin
  Info.dwOSVersionInfoSize := SizeOf(Info);
  GetVersionEx(Info);
  if (Info.dwPlatformId = VER_PLATFORM_WIN32_NT) and
    (Info.dwMajorVersion >= 5) then
  begin
    SetLayeredWindowAttributes := GetProcAddress(GetModulehandle(user32),'SetLayeredWindowAttributes');
    if Assigned(SetLayeredWindowAttributes) then
    begin
      SetWindowLong(AHandle, GWL_EXSTYLE, GetWindowLong(AHandle, GWL_EXSTYLE) or WS_EX_LAYERED);
      SetLayeredWindowAttributes(AHandle, 0, AValue, LWA_ALPHA);
    end;
  end;
end;

end.




uses
  ..., trans;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MakeTransparent(Handle, 120);
end;
Du kannst damit auch Dialoge transparent machen:
Delphi-Quellcode:
procedure TForm1.FontDialogShow(Sender: TObject);
begin
  MakeTransparent(FontDialog.Handle, 100);
end;
  Mit Zitat antworten Zitat