1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
| unit Unit8;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TBackgroundForm = class(TForm)
protected
procedure DoClose(var Action: TCloseAction); override;
procedure Refresh;
procedure WMWindowPosChanged(var Message :TMessage); message WM_WINDOWPOSCHANGED;
public
constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override;
end;
TTopForm = class(TForm)
Button1: TButton;
Memo1: TMemo;
private
BkForm :TBackgroundForm;
public
constructor Create(aOwner :TComponent); override;
end;
var
TopForm: TTopForm;
implementation
{$R *.dfm}
constructor TTopForm.Create(aOwner: TComponent);
begin
inherited;
//Fiche transparente
BorderStyle := bsNone;
TransparentColorValue := Color;
TransparentColor := TRUE;
//Fond
BkForm := TBackgroundForm.CreateNew(Self);
end;
{ TBackgroundForm }
procedure TBackgroundForm.DoClose(var Action: TCloseAction);
begin
TForm(Owner).Close;
end;
constructor TBackgroundForm.CreateNew(AOwner: TComponent; Dummy: Integer);
begin
inherited;
AlphaBlend := TRUE;
AlphaBlendValue := 200;
BoundsRect := TControl(Owner).BoundsRect;
Caption := TForm(Owner).Caption;
Show;
Refresh;
end;
procedure TBackgroundForm.WMWindowPosChanged(var Message: TMessage);
begin
inherited;
if not (csDestroying in ComponentState) then
TForm(Owner).BoundsRect := BoundsRect;
end;
procedure TBackgroundForm.Refresh;
var
i :integer;
R1, R2 :hRgn;
begin
//Découpe les zones où doivent apparaître les Controls
R1 := CreateRectRgn(0, 0, Width, Height);
with TForm(Owner) do
for i := 0 to ControlCount -1 do
with Controls[i].BoundsRect do
begin
R2 := CreateRectRgn(Left, Top, Right, Bottom);
CombineRgn(R1, R1, R2, RGN_XOR);
DeleteObject(R2);
end;
SetWindowRgn(handle, R1, TRUE);
DeleteObject(R1);
end;
end. |
Partager