unit Unit2;
interface
uses Forms, IniFiles, Windows, Classes;
type
Bytes =
array of byte;
procedure SaveWindowPlacement(pvForm: TForm; pvIniFile:
String);
procedure RestoreWindowPlacement(pvForm: TForm; pvIniFile:
String);
implementation
procedure SaveWindowPlacement(pvForm: TForm; pvIniFile:
String);
var lvIniFile: TIniFile;
lvWindowPlacement: Bytes;
function WindowPlacementToStr(pvWindowPlacement: Bytes):
String;
var lvSize: Byte;
begin
lvSize := SizeOf(TWindowPlacement);
SetLength(Result,lvSize*2);
BinToHex(@pvWindowPlacement[0],@Result[1],lvSize);
end;
begin
if pvForm =
nil then Exit;
if Length(pvIniFile)=0
then Exit;
lvIniFile := TIniFile.Create(pvIniFile);
SetLength(lvWindowPlacement,SizeOf(TWindowPlacement));
TWindowPlacement((@lvWindowPlacement[0])^).length:=SizeOf(TWindowPlacement);
if Windows.GetWindowPlacement(pvForm.Handle, @lvWindowPlacement[0])
then
begin
lvIniFile.WriteString(pvForm.
Name,'
WindowPlacement',WindowPlacementToStr(lvWindowPlacement));
end;
lvIniFile.Free;
end;
procedure RestoreWindowPlacement(pvForm: TForm; pvIniFile:
String);
var lvIniFile: TIniFile;
lvWindowPlacement: Bytes;
function StrToWindowPlacement(pvWindowPlacement:
String): Bytes;
var lvSize: Byte;
begin
lvSize := SizeOf(TWindowPlacement);
if length(pvWindowPlacement)<>(lvSize*2)
then Result :=
nil;
SetLength(Result,lvSize);
HexToBin(@pvWindowPlacement[1],@Result[0],lvSize);
end;
begin
if pvForm =
nil then Exit;
if Length(pvIniFile)=0
then Exit;
lvIniFile := TIniFile.Create(pvIniFile);
if lvIniFile.ValueExists(pvForm.
Name,'
WindowPlacement')
then
begin
lvWindowPlacement := StrToWindowPlacement(lvIniFile.ReadString(pvForm.
Name,'
WindowPlacement','
'));
if lvWindowPlacement <>
nil then Windows.SetWindowPlacement(pvForm.Handle,@lvWindowPlacement[0]);
end;
end;
end.