procedure TCustomForm.SetAlphaBlend(
const Value: Boolean);
begin
if FAlphaBlend <> Value
then
begin
FAlphaBlend := Value;
SetLayeredAttribs;
end;
end;
procedure TCustomForm.SetAlphaBlendValue(
const Value: Byte);
begin
if FAlphaBlendValue <> Value
then
begin
FAlphaBlendValue := Value;
SetLayeredAttribs;
end;
end;
procedure TCustomForm.InitAlphaBlending(
var Params: TCreateParams);
begin
if not (csDesigning
in ComponentState)
and (assigned(SetLayeredWindowAttributes))
then
if FAlphaBlend
or FTransparentColor
then
Params.ExStyle := Params.ExStyle
or WS_EX_LAYERED;
end;
procedure TCustomForm.SetLayeredAttribs;
const
cUseAlpha:
array [Boolean]
of Integer = (0, LWA_ALPHA);
cUseColorKey:
array [Boolean]
of Integer = (0, LWA_COLORKEY);
var
AStyle: Integer;
begin
if not (csDesigning
in ComponentState)
and
(Assigned(SetLayeredWindowAttributes))
and HandleAllocated
then
begin
AStyle := GetWindowLong(
Handle, GWL_EXSTYLE);
if FAlphaBlend
or FTransparentColor
then
begin
if (AStyle
and WS_EX_LAYERED) = 0
then
SetWindowLong(
Handle, GWL_EXSTYLE, AStyle
or WS_EX_LAYERED);
SetLayeredWindowAttributes(
Handle, FTransparentColorValue, FAlphaBlendValue,
cUseAlpha[FAlphaBlend]
or cUseColorKey[FTransparentColor]);
end
else
begin
SetWindowLong(
Handle, GWL_EXSTYLE, AStyle
and not WS_EX_LAYERED);
RedrawWindow(
Handle,
nil, 0, RDW_ERASE
or RDW_INVALIDATE
or RDW_FRAME
or RDW_ALLCHILDREN);
end;
end;
end;