Transparent Form: Done differently by capturing form ! lazarus / 39-Graphics ---------------------------------------------------------------------- Boleeman · 2026-02-03 08:20 LV and myself have done it a different way by capturing underneath. I tried doing layering the VB6 way but the form was always see through when clicking. Find it a bit funny that good old VB6 could create and draw to a glass/transparent layer but Lazarus was not able to have the same click on glass layer behavior. Still searching for a way to tell Lazarus "if the layer is totally transparent then make an exception and draw to it" like VB6 does. In Lazarus I came close to it, but the layer is slightly "frosty glass" in appearance. (see last png attachment in this 1st message) Hi All. I have been wanting to create a Transparent Form where you Show All Controls but the form is Not Click Through. The program like an overlayed tracing app. I have found some code by KodeZwerg that Shows all Controls on the transparent form but when clicking on the transparent part I need to NOT click through the form but CLICK and DRAG ONTO IT (as I want to draw on it). I have an old VB6 code that does it well that uses vbCyan as a Chroma Key to make the form perfectly transparent, but I can't seem to work out how to not click through the transparent form in Lazarus? (the VB6 code uses api, I had to remove the VB6  Dialogue control as it did not work in Windows 10). I have attached the VB6 source just in case someone wants to look at the original VB6 source. What I was wanting to achieve is to use Lazarus to create a resizable and moveable transparent form that can be clicked onto, with the controls fully showing. Not sure if TBgrabmp or TBGRAVirtualScreen might be better to use? Hopefully someone can possibly help me out, as I seem to be stuck on being able to NOT CLICK THROUGH the Transparent Form but click onto it? ---------------------------------------------------------------------- circular · 2026-02-03 12:00 Hi Boleeman, There are two approaches I can imagine: - To have the background of the form not totally transparent but a very transparent gray like BGRA(192, 192, 192, 1) - To make a copy of the area of the screen and draw it inside the form, so the form would not be transparent, at least when you would like the user to draw Regards ---------------------------------------------------------------------- Fred vS · 2026-02-03 12:09 Hello. I think that you can do it with MSEgui: https://github.com/mse- org/mseide-msegui/discussions/52 ---------------------------------------------------------------------- Boleeman · 2026-02-04 11:38 Thanks Guys for replying. I will try a few suggested things out. Circular, I found a Lazarus sample code that uses in Form1:   AlphaBlend := True;   AlphaBlendValue := 10;  // set to 1 if no background is needed   BorderStyle := bsNone; and in Form 2 it uses a fixed array of 13 points arrPts: array[0..12] of TPoint;  to cut off everything outside the polygon but fully show the controls, with the transparent Form1 not click through. which is similar to what you suggested: have the background of the form not totally transparent but a very transparent gray like BGRA(192, 192, 192, 1) but uses AlphaBlendValue := 10; instead of 1. Fred vS, I downloaded mseuniverse with that MSEgui example. I was always curious about MSEgui. I know it makes GUI's but never really used it but will also have a play with that new shape in optionswindow: wo_transparentbackground. Sounds interesting. Also read up about Martin Schreiber in the Biography of Martin. Very intelligent. I also found a Lazarus example on the forum that uses a similar SetLayeredWindowAttributes api: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, LCLType, LCLIntf; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure FormCreate(Sender: TObject);  private   public   end; const      LWA_COLORKEY = 1;      LWA_ALPHA = 2;      LWA_BOTH = 3;      WS_EX_LAYERED = $80000;      GWL_EXSTYLE = -20; var  Form1: TForm1; implementation {$R *.lfm} {Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal Color As Long, ByVal X As Byte, ByVal alpha As Long) As Boolean }function SetLayeredWindowAttributes(hWnd: longint; Color: longint;  X: byte; alpha: longint): bool stdcall; external 'USER32'; {not sure how to alias these functions here ????   alias setwindowlonga!!}{Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long }function SetWindowLongA(hWnd: longint; nIndex: longint;  dwNewLong: longint): longint stdcall; external 'USER32'; {Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long }function GetWindowLongA(hWnd: longint; nIndex: longint): longint stdcall;  external 'user32'; procedure SetTranslucent(ThehWnd: longint; Color: longint; nTrans: integer);var  Attrib: longint;begin  {SetWindowLong and SetLayeredWindowAttributes are API functions, see MSDN for details }  Attrib := GetWindowLongA(ThehWnd, GWL_EXSTYLE);  SetWindowLongA(ThehWnd, GWL_EXSTYLE, attrib or WS_EX_LAYERED);  {anything with color value color will completely disappear if flag = 1 or flag = 3  }  SetLayeredWindowAttributes(ThehWnd, Color, nTrans, 1);end; procedure TForm1.FormCreate(Sender: TObject);var  Transparency: longint;begin  Self.Color := clRed;  Transparency := Self.Color;  SetTranslucent(Self.Handle, Transparency, 0);end;  end. Looking at it and comparing it to the VB6 code: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ' Window StylePublic Const GWL_STYLE = (-16)Public Const WS_SYSMENU = &H80000Public Const WS_MINIMIZEBOX = &H20000Private Const GWL_EXSTYLE = (-20)Private Const WS_EX_LAYERED = &H80000    ' TransparencyPrivate Const LWA_COLORKEY = &H1Private Const LWA_ALPHA = &H2 ' Mouse CapturePublic Const WM_NCLBUTTONDOWN = &HA1Public Const HTCAPTION = 2 ' Window PositionPrivate Const GW_HWNDNEXT = 2 Public hTaskBar As Long Public Sub SetTrans(oForm As Form, Optional bytAlpha As Byte = 255, Optional lColor As Long = 0)    Dim lStyle As Long    lStyle = GetWindowLong(oForm.hWnd, GWL_EXSTYLE)    If Not (lStyle And WS_EX_LAYERED) = WS_EX_LAYERED Then _        SetWindowLong oForm.hWnd, GWL_EXSTYLE, lStyle Or WS_EX_LAYERED    SetLayeredWindowAttributes oForm.hWnd, lColor, bytAlpha, LWA_COLORKEY Or LWA_ALPHAEnd Sub     Private Sub Form_Load()    Set fEvents = frmBlank        ' ShowInTaskBar    SetWindowLong Me.hWnd, GWL_STYLE, GetWindowLong(Me.hWnd, GWL_STYLE) Or WS_SYSMENU Or WS_MINIMIZEBOX      ' Set Transparency Colour    Me.BackColor = vbCyan    SetChildColour Me.BackColor        ' Set Transparency    SetTrans Me, , Me.BackColor  SetTrans fEvents, 1    ' If the mouse-clicks are passing through then try increasing the number    ' e.g. SetTrans fEvents, 5        'Center    Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2    PopulateControls            Me.Show    ltbID = GetAppsID(Me.Caption)    fEvents.Show    Me.ZOrderEnd Sub Private Sub Form_Unload(Cancel As Integer)    Me.Visible = False    fEvents.Visible = False    SetTrans Me    SetTrans fEvents    Unload fEvents    Set fEvents = Nothing    Set picUndo = NothingEnd Sub ' GeneralPublic Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _    ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _    ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long    ' Process And MemoryPrivate Declare Function GetWindowThreadProcessId Lib "user32" ( _    ByVal hWnd As Long, lpdwProcessId As Long) As Long    Private Declare Function OpenProcess Lib "kernel32" ( _    ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long    Private Declare Function CloseHandle Lib "kernel32" ( _    ByVal hObject As Long) As Long    Private Declare Function VirtualFreeEx Lib "kernel32" ( _    ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal dwFreeType As Long) As Long    Private Declare Function VirtualAllocEx Lib "kernel32" ( _    ByVal hProcess As Long, lpAddress As Any, ByRef dwSize As Long, ByVal flAllocationType As Long, _    ByVal flProtect As Long) As Long    Private Declare Function ReadProcessMemory Lib "kernel32" ( _    ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, _    Optional lpNumberOfBytesWritten As Long) As Long ' Setting Window StylePublic Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" ( _    ByVal hWnd As Long, ByVal nIndex As Long) As Long Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _    ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long ' TransparencyPrivate Declare Function SetLayeredWindowAttributes Lib "user32" ( _    ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long ' Control PositionPrivate Declare Function GetWindowRect Lib "user32" ( _    ByVal hWnd As Long, lpRect As RECT) As Long Private Declare Function ClientToScreen Lib "user32" ( _    ByVal hWnd As Long, lpPoint As POINTAPI) As Long ' Window PositionPrivate Declare Function GetWindow Lib "user32" ( _    ByVal hWnd As Long, ByVal wCmd As Long) As Long ' Mouse CapturePublic Declare Function ReleaseCapture Lib "user32" () As LongPublic Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long As the Lazarus parts look similar to the VB6 api code I might be able to replicate the VB6 form transparency behaviour. Attached below is the VB6 source in a text file, with the form code and module code that contains the api. The vb6 code uses     Me.BackColor = vbCyan and SetChildColour Me.BackColor and  SetTrans fEvents, 1 The Lazarus code uses   Self.Color := clRed; and Transparency := Self.Color; and SetTranslucent(Self.Handle, Transparency, 0); ---------------------------------------------------------------------- Fred vS · 2026-02-04 12:58 Quote from: Boleeman on February 04, 2026, 12:38:55 pmFred vS, I downloaded mseuniverse with that MSEgui example. I was always curious about MSEgui. I know it makes GUI's but never really used it but will also have a play with that new shape in optionswindow: wo_transparentbackground. Sounds interesting. Also read up about Martin Schreiber in the Biography of Martin. Very intelligent. Hello Boleeman. Yes, Martin is a extremely precious gem. MSEgui is also fully compatible with BGRAbitmap, I  used some of your great code for a MSEgui app (see picture). ---------------------------------------------------------------------- Boleeman · 2026-02-06 11:48 I have tried working on the VB6 Transparent Form conversion Got Some Things Working OK and Others Not ! Consists of 2 Forms (Rendering and EventForm) Working: Got it Transparent. On Top working. Sizing and Moving Corner Controls are working. Other controls are visible and aligned to left side. Not Working: Clicking onto canvas goes through Form. Drawing lines and shapes onto canvas not rendering/working. Attached below is what I have. Perhaps someone else might be able to fix those faulty "needed features" so we get some rendering? Screenshot is of Lazarus version showing transparency. Drawing features not working. Frustrating! ---------------------------------------------------------------------- Xenno · 2026-02-06 12:27 Snippet below can make transparent form excluding title bar. Perhaps, it could help somehow. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses Windows; procedure PrcTransparentForm(PrmForm: TForm; PrmClr: TColor);begin  PrmForm.Color := PrmClr; // unique mask color  SetWindowLong(PrmForm.Handle, GWL_EXSTYLE,      GetWindowLong(PrmForm.Handle, GWL_EXSTYLE) or WS_EX_LAYERED);  SetLayeredWindowAttributes(PrmForm.Handle, PrmClr, 255, LWA_COLORKEY);end; ---------------------------------------------------------------------- Boleeman · 2026-02-06 13:34 Thanks Xenno. Yes that is transparent, but it clicks through the form rather than onto it. I am trying to work out how NOT to click through the form ---------------------------------------------------------------------- Xenno · 2026-02-07 03:50 How about adding a "restricted area"? Intercept WM_MOUSEMOVE and kick the cursor out when it was entering it. ---------------------------------------------------------------------- LV · 2026-02-07 14:24 I believe you are looking for something like this. 🤔 ---------------------------------------------------------------------- LV · 2026-02-07 16:53 Oh, I forgot to attach the code. It was tested on Windows 11, using Laz 3.4 and FPC 3.2.2. P.S. Essentially, what @circular mentioned earlier has been implemented here. "To make a copy of the area of the screen and draw it inside the form, so the form would not be transparent, at least when you would like the user to draw" ---------------------------------------------------------------------- Boleeman · 2026-02-08 02:09 Thanks LV for your sample code. Believe it or not, I was doing something similar. Great minds think alike ! I sort of call it "the cheaters mode" as it really is capturing what is below, rather than having a floating layer. I really wanted another invisible layer to be drawn on top, but beggars can't be choosers. As the Lazarus form is fully maximized, use Alt F4 to exit out of program Probably need to set up a shortcut). In the text mode, I wanted to add a blinking text but it was buggy. Can change to size and color of the text, but perhaps angling would be nice. Press Ctrl when drawing rectangles and ellipses makes them squares and circles. Can also fill rectangles and ellipses. I think the best way of loading the program is display what you want on desktop and have a shortcut in the taskbar to start the program. Poly and Erase still to be done. Undo needs some work. Not sure why, but when doing text characters appear in the text size TSpinEdit seSize? (seen in the screenshot) Enjoy ! ---------------------------------------------------------------------- LV · 2026-02-08 07:38 Quote from: Boleeman on February 08, 2026, 03:09:13 amI sort of call it "the cheaters mode" I would call it the "David Copperfield mode". 😁