Einzelnen Beitrag anzeigen

Lemmi

Registriert seit: 8. Aug 2006
11 Beiträge
 
#1

Komponente als Handle benutzen / Form1.Alphablend übertragen

  Alt 12. Aug 2006, 12:44
Hi Delphianer,

Ich möchte auf meiner Form ein Hintergrundbild haben und buttons, memos etc. leicht transparent haben.Nun habe ich folgenden Code gefunden, mitdem man das komplette formular transparent machen konnte.

1.Ansatz

Delphi-Quellcode:
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;

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

procedure SetTransparentForm(AHandle : THandle; AValue : byte = 0);
var
 Info: TOSVersionInfo;
 SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
begin
 //Check Windows version
 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);
        //Make form transparent
        SetLayeredWindowAttributes(AHandle, 0, AValue, LWA_ALPHA);
      end;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  SetTransparentForm(Handle,150);
end;
Kann ich diese Procedure auch irgendwie auf Komponenten anwenden? Hat jemand einen besseren Vorschlag, wie ich das realisieren kann, z.B. die Alphablend-Eigenschaft von TForm auf andere Komponenten übertragen kann?

2.Ansatz

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
 Form2 := TForm2.Create(Application);
 Form2.Top := 0;
 Form2.Left := 0;
 Form2.Parent := Form1;
 Form2.AlphaBlend := true;
 Form2.AlphaBlendValue := 150;
 Form2.visible := True;
end;
Problem hierbei ist: Form2 wird nicht transparent, da form1 nicht transparent ist....

Freue mich über jeden Ratschlag

Gruß, Lemming
Es gibt kein Problem, aber ich arbeite dran.
  Mit Zitat antworten Zitat