Искал на форуме сабж ничего подобного не нашёл.
Гуглил "прозрачная форма Lazarus", аналогично.
Вопрос: Как в Lazarus сделать форму прозрачной?
Модератор: Модераторы
SetWindowLong((Self as TForm).Handle, GWL_EXSTYLE, GetWindowLong((Self as TForm).Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes((Self as TForm).Handle, 0, 200, LWA_ALPHA);
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong((Self as TForm).Handle, GWL_EXSTYLE, GetWindowLong((Self as TForm).Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes((Self as TForm).Handle, 0, 200, LWA_ALPHA);
end;
function SetLayeredWindowAttributes; external 'user32.dll';
User32 := SafeLoadLibrary('user32.dll');
type
...
TSetLayeredWindowAttributes = function (hWnd: HWND; crKey: TColorRef; bAlpha: byte; dwFlags: LongWord): LongBool; stdcall;
const
LWA_COLORKEY = 1;
LWA_ALPHA = 2;
procedure TForm1.FormCreate(Sender: TObject);
var
TransparencyColor: TColorRef;
Translucency: Byte;
SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
USER32: HMODULE;
begin
TransparencyColor := clBlue;
Translucency := (255 * 50) div 100;
User32 := SafeLoadLibrary('user32.dll');
if User32 <> 0 then
begin
SetLayeredWindowAttributes := GetProcAddress(User32,
'SetLayeredWindowAttributes');
if @SetLayeredWindowAttributes <> nil then
SetLayeredWindowAttributes(Handle, TransparencyColor, Translucency,
LWA_ALPHA or LWA_COLORKEY);
FreeLibrary(User32);
end;
...
const
LWA_ALPHA = 2;
WS_EX_LAYERED = $80000;
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
windows;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
SetWindowLong((Self as TForm).Handle, GWL_EXSTYLE, GetWindowLong((Self as TForm).Handle, GWL_EXSTYLE) or WS_EX_LAYERED);
SetLayeredWindowAttributes((Self as TForm).Handle, 0, 100, LWA_ALPHA);
// Третий параметр отвечает за степень прозрачности. От 0 до 255
end;
initialization
{$I unit1.lrs}
end.
Сейчас этот форум просматривают: Google [Bot] и гости: 7