procedure TForm1.Timer1Timer(Sender: TObject);
var
hWindow : HWnd;
r : TRect;
Breite : Integer;
Hoehe : Integer;
begin
//Wenn nicht aktiviert, dann verlasse
if checkbox1.Checked = false
then exit;
//Holfe Handle und Position des aktiven Fensters
hWindow := GetForegroundWindow;
GetWindowRect(hWindow, r);
//Berechnen von Breite und Höhe
Breite := screen.Width-r.left-(screen.Width-r.right);
Hoehe := screen.Height-r.top-(screen.Height-r.Bottom);
//Linker Rand
if (r.Left <= spinedit1.Value)
AND (r.Left >= -spinedit1.Value)
then MoveWindow(hwindow,0,r.Top,Breite,Hoehe,True);
//Rechter Rand
if (r.Right >= (screen.Width-spinedit1.Value))
AND (r.Right <= (screen.Width + spinedit1.Value))
then MoveWindow(hwindow,screen.Width-Breite,r.Top,Breite,Hoehe,True);
//Oben
if (r.Top <= spinedit1.Value)
AND (r.Top >= -spinedit1.Value)
then Movewindow(hwindow,r.Left,0,Breite,Hoehe,True);
//Unten
if (r.Bottom >= (screen.height-spinedit1.Value))
AND (r.Bottom <= (screen.Height + spinedit1.Value))
then MoveWindow(hwindow,r.Left,screen.Height-Hoehe,Breite,Hoehe,True);
end;