Einzelnen Beitrag anzeigen

Heffalump

Registriert seit: 3. Aug 2005
278 Beiträge
 
RAD-Studio 2009 Ent
 
#8

Re: Ist Programm minimiert / in der Taskleiste?

  Alt 10. Jun 2006, 11:55
Und noch eine komplizierte Lösung (welchen nicht nur den minimiert oder maximiert Status speichert)
Delphi-Quellcode:
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.
  Mit Zitat antworten Zitat