uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private-Deklarationen }
bmp: TBitmap;
procedure WMNCHitTest(
var aMessage: TWMNCHitTest);
message WM_NCHITTEST;
procedure WMWindowPosChanging(
var aMessage: TWMWindowPosChanging);
message WM_WINDOWPOSCHANGING;
procedure WMEraseBkgnd(
var aMessage: TWMEraseBkgnd);
message WM_ERASEBKGND;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
Rgn : HRGN;
function CreateRgnFromRect(ARect: TRect): HRGN;
begin
Result := CreateRectRgn(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
bmp := TBitmap.Create;
bmp.PixelFormat := pf24Bit;
bmp.Width := Self.ClientWidth;
bmp.Height := Self.ClientHeight;
Rgn := CreateRgnFromRect(Self.ClientRect);
SetWindowRgn(
Handle, Rgn, TRUE);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
bmp.Free;
end;
procedure TForm1.WMNCHitTest(
var aMessage: TWMNCHitTest);
var
p : tpoint;
begin
inherited;
p.x := aMessage.XPos;
p.y := aMessage.YPos;
p := screenToClient(p);
if PtInRect(Self.Clientrect, p)
then
aMessage.Result := HTCAPTION;
end;
procedure TForm1.WMWindowPosChanging(
var aMessage: TWMWindowPosChanging);
var
ScrDC: HDC;
p: TPoint;
begin
inherited;
if isWindowVisible(Self.Handle)
then
begin
p.x := aMessage.WindowPos.x;
p.y := aMessage.WindowPos.y;
bmp.Canvas.Brush.Style := bsSolid;
bmp.Canvas.Pen.Color := clGreen;
bmp.Canvas.FillRect(Self.Clientrect);
// Screen to Bitmap
ScrDC := GetDC(0);
BitBlt(
bmp.Canvas.Handle,
0,
0,
bmp.Width,
bmp.Height,
ScrDC,
p.x,
p.y,
SRCCOPY
);
ReleaseDC(0, ScrDC);
Self.Paint;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
if isWindowVisible(Self.Handle)
and Assigned(bmp)
then
Self.Canvas.Draw(0,0, bmp);
end;
procedure TForm1.WMEraseBkgnd(
var aMessage: TWMEraseBkgnd);
begin
aMessage.Result := 0;
end;
end.