SetWindowTransparency
Delphi
function SetWindowTransparency (WndHandle: HWND; 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 to true, then invoke this function and pass the handle of the form to make transparent. Sample code is available in the transparency checkbox code of the "display" tab of the MainDemo project.
Parameters:
-
WndHandle: handle of the window or form to make transparent.
-
UseColorKey: if true, the transparency uses the color key of TVideoGrabber (ColorKey).
-
UseAlpha: if true, the transparency uses the AlphaValue alpha blending value.
-
AlphaValue: alpha blending value, used when UseAlpha is true.
E.g. in Delphi:
procedure TfrmMainForm.chkTransparencyClick(Sender: TObject);
begin
// in this sample the transparent window is created below when the color key is enabled
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, false, 0);
FTransparentForm.Show;
end;
end;