// Non sizible Form
procedure SetStaticWindow(aForm: TForm);
var
r: TRect;
begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);
if aForm.Height > r.Bottom then aForm.Height := r.Bottom;
if aForm.Top < 0 then aForm.Top := 0;
if aForm.Top+aForm.Height > r.Bottom then
aForm.Top := r.Bottom-aForm.Height;
if aForm.Left+aForm.Width > r.Right then
aForm.Left := r.Right-aForm.Width;
if aForm.Left < 0 then aForm.Left := 0;
end;
// Sizible Form
procedure SetDynamicWindow(aForm: TForm);
var
r: TRect;
begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);
if aForm.Height > r.Bottom then aForm.Height := r.Bottom;
if aForm.Top < 0 then aForm.Top := 0;
if aForm.Top+aForm.Height > r.Bottom then
aForm.Top := r.Bottom-aForm.Height;
if aForm.Left+aForm.Width > r.Right then
aForm.Left := r.Right-aForm.Width;
if aForm.Left < 0 then aForm.Left := 0;
if aForm.Width > r.Right then aForm.Width := r.Right;
end;
// Set Form pos on ref Form
procedure SetWindowCenterOnWindow(FormCenter, FormReference: TForm);
var
r: TRect;
begin
SystemParametersInfo(SPI_GETWORKAREA, 0, @r, 0);
if (FormReference = nil) then begin
FormCenter.Left := (r.Right div 2) - (FormCenter.Width div 2);
FormCenter.Top := (r.Bottom div 2) - (FormCenter.Height div 2);
Exit;
end;
if (not FormReference.Visible) then begin
FormCenter.Left := (r.Right div 2) - (FormCenter.Width div 2);
FormCenter.Top := (r.Bottom div 2) - (FormCenter.Height div 2);
Exit;
end;
FormCenter.Left := ((FormReference.Width div 2) +
FormReference.Left) - (FormCenter.Width div 2);
FormCenter.Top := ((FormReference.Height div 2) +
FormReference.Top) - (FormCenter.Height div 2);
SetStaticWindow(FormCenter);
end;