uses
windows, forms, registry;
procedure StoreFormPos(aForm: TForm; aRegPath:
string);
var
Placement: TWindowPlacement;
Section:
string;
begin
if assigned(aForm)
then with TRegistryIniFile.Create(aRegPath)
do try
Placement.Length := SizeOf(TWindowPlacement);
GetWindowPlacement(aForm.Handle, @Placement);
Section:=aForm.
Name;
with Placement, aForm
do begin
if (aForm = Application.MainForm)
and IsIconic(Application.Handle)
then
ShowCmd := SW_SHOWMINIMIZED;
if (FormStyle = fsMDIChild)
and (WindowState = wsMinimized)
then
Flags:=Flags
or WPF_SETMINPOSITION;
WriteInteger(Section, '
Flags', Flags);
WriteInteger(Section, '
ShowCmd', ShowCmd);
WriteInteger(Section, '
Pixels', Screen.PixelsPerInch);
WriteInteger(Section, '
MaxX', ptMaxPosition.X);
WriteInteger(Section, '
MaxY', ptMaxPosition.Y);
WriteInteger(Section, '
MinX', ptMinPosition.X);
WriteInteger(Section, '
MinY', ptMinPosition.Y);
WriteInteger(Section, '
Left', rcNormalPosition.Left);
WriteInteger(Section, '
Top', rcNormalPosition.Top);
WriteInteger(Section, '
Right', rcNormalPosition.Right);
WriteInteger(Section, '
Bottom', rcNormalPosition.Bottom);
end;
finally
Free;
end
end;
procedure RestoreFormPos(aForm: TForm; aRegPath:
string);
var
Placement: TWindowPlacement;
Section:
string;
begin
if assigned(aForm)
then with TRegistryIniFile.Create(aRegPath)
do try
Placement.Length := SizeOf(TWindowPlacement);
GetWindowPlacement(aForm.Handle, @Placement);
Section:=aForm.
Name;
if Screen.PixelsPerInch=ReadInteger(Section, '
Pixels', 0)
then with Placement, aForm
do begin
Flags:=ReadInteger(Section, '
Flags', Flags);
ShowCmd:=ReadInteger(Section, '
ShowCmd', ShowCmd);
ptMaxPosition.X:=ReadInteger(Section, '
MaxX', ptMaxPosition.X);
ptMaxPosition.Y:=ReadInteger(Section, '
MaxY', ptMaxPosition.Y);
ptMinPosition.X:=ReadInteger(Section, '
MinX', ptMinPosition.X);
ptMinPosition.Y:=ReadInteger(Section, '
MinY', ptMinPosition.Y);
rcNormalPosition.Left:=ReadInteger(Section, '
Left', rcNormalPosition.Left);
rcNormalPosition.Top:=ReadInteger(Section, '
Top', rcNormalPosition.Top);
rcNormalPosition.Right:=ReadInteger(Section, '
Right', rcNormalPosition.Right);
rcNormalPosition.Bottom:=ReadInteger(Section, '
Bottom', rcNormalPosition.Bottom);
SetWindowPlacement(
Handle, @Placement);
end;
// Formular nicht gespeichert oder Auflösung geändert
finally
Free;
end
end;