Skip to content

SetWindowTransparency

function

Delphi
function SetWindowTransparency (WndHandle: NativeInt; UseColorKey: Boolean; UseAlpha: Boolean; AlphaValue: LongInt): Boolean;
C++Builder
bool __fastcall SetWindowTransparency(HWND WndHandle, bool UseColorKey, bool UseAlpha, System::LongInt AlphaValue);
C#
public bool SetWindowTransparency(IntPtr WndHandle, bool UseColorKey, bool UseAlpha, int AlphaValue);
VB.NET
Public Function SetWindowTransparency(WndHandle As IntPtr, UseColorKey As Boolean, UseAlpha As Boolean, AlphaValue As Integer) As Boolean
C++/Qt
BOOL SetWindowTransparency (HWND WndHandle, BOOL UseColorKey, BOOL UseAlpha, int AlphaValue);

Sets the transparency (color key or alpha value) on a window or form. Set ColorKeyEnabled = true, then invoke this function and pass the handle to the form to be made transparent. Sample code is available in the transparency checkbox code of the "display" tab of the MainDemo project.

E.g. in Delphi:

procedure TfrmMainForm.chkTransparencyClick(Sender: TObject);

begin

// in this sample the transparent window is created in the VideoGrabberColorKeyChange

// event below when the color key is set

VideoGrabber.ColorKeyEnabled := chkTransparency.Checked;

if VideoGrabber.ColorKeyEnabled then begin

if not assigned (FTransparentForm) then begin

Application.CreateForm (TForm, FTransparentForm);

FTransparentForm.Width := 300;

FTransparentForm.Height := 100;

FTransparentForm.Position := poScreenCenter;

FTransparentForm.FormStyle := fsStayOnTop;

FTransparentPanel := TPanel.Create (FTransparentForm);

FTransparentPanel.Parent := FTransparentForm;

FTransparentPanel.BevelInner := bvNone;

FTransparentPanel.BevelOuter := bvNone;

FTransparentPanel.Align := alClient;

FTransparentPanel.Caption := 'transparent window';

FTransparentPanel.Font.Color := clRed;

FTransparentPanel.Font.Size := 16;

end;

FTransparentForm.Color := clBlue;

FTransparentPanel.Color := VideoGrabber.ColorKey;

VideoGrabber.SetWindowTransparency (FTransparentForm.Handle, true, VideoGrabber.ColorKey, false, 0);

FTransparentForm.Show;

end;

end;