1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
procedure EcrirePositionFenetre(Form: TForm;Fenetre: String);
function LirePositionFenetre(Form: TForm; Fenetre: String): Boolean;
procedure EcrirePositionFenetre(Form: TForm;Fenetre: String);
var
WindowPlacement : TWindowPlacement;
Begin
WindowPlacement.length:=SizeOf(WindowPlacement);
WindowPlacement.flags := 0;
WindowPlacement.showCmd := 1;
// récupération de l'emplacement ou se situe la fiche lorsque WindowState est en wsNormal
GetWindowPlacement(Form.Handle,@WindowPlacement);
With Fichier_ini do
Begin
// On créer ou on lit le fichier
Fichier_Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) +'.txt');
Try
// On alimente la section
WriteInteger(Fenetre, 'Left', WindowPlacement.rcNormalPosition.Left);
WriteInteger(Fenetre, 'Top', WindowPlacement.rcNormalPosition.Top);
WriteInteger(Fenetre, 'Height', WindowPlacement.rcNormalPosition.Bottom - WindowPlacement.rcNormalPosition.Top);
WriteInteger(Fenetre, 'Width', WindowPlacement.rcNormalPosition.Right - WindowPlacement.rcNormalPosition.Left);
Finally
if Assigned(Fichier_ini) then Fichier_Ini.Free;
end;
end;
end;
function LirePositionFenetre(Form: TForm; Fenetre: String): Boolean;
Begin
Result := False;
// On créer ou on lit le fichier
Fichier_Ini := TIniFile.Create(ExtractFilePath(Application.ExeName) +'.txt');
Try
if Fichier_Ini.SectionExists(Fenetre) then
begin
// On récupère les données si il y en à
Form.Left := Fichier_Ini.ReadInteger(Fenetre, 'Left', 0);
Form.Top := Fichier_Ini.ReadInteger(Fenetre, 'Top', 0);
// si la fenêtre n'ai pas taillable Height, Width reste inchangé (même si on touche directement le ini)
if Form.BorderStyle <> bsSingle then
begin
Form.Height := Fichier_Ini.ReadInteger(Fenetre, 'Height', 08);
Form.Width := Fichier_Ini.ReadInteger(Fenetre, 'Width', 0);
end;
Result := True;
end;
Finally
if Assigned(Fichier_ini) then Fichier_Ini.Free;
end;
end; |
Partager