1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| type
TWinControlHelper = class helper for TWinControl
procedure SetOpacity(aOpacity :byte; aTransparentColor :TColor = clNone);
end;
uses System.Math;
procedure TWinControlHelper.SetOpacity(aOpacity: byte; aTransparentColor :TColor);
begin
var ExStyle := GetWindowLongPtr(Handle, GWL_EXSTYLE);
var Flags := IfThen(aOpacity < High(aOpacity), LWA_ALPHA) or
IfThen(aTransparentColor <> clNone, LWA_COLORKEY);
if Flags <> 0 then
begin
SetWindowLongPtr(Handle, GWL_EXSTYLE, ExStyle or WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, aTransparentColor, aOpacity, Flags);
end
else SetWindowLongPtr(Handle, GWL_EXSTYLE, ExStyle and not WS_EX_LAYERED)
end; |
Partager