Einzelnen Beitrag anzeigen

ToZie

Registriert seit: 17. Feb 2004
43 Beiträge
 
Delphi 10.3 Rio
 
#133

Re: PlainEdit 1.7.4 - Texteditor für Windows

  Alt 4. Mai 2008, 15:12
Zitat von Gaijin:
Zitat von ToZie:
War PlainEdit allerdings maximiert startet es beim nächten Aufruf maximiert auf meinem primären Monitor, auch wenn es sich beim letzten Schließen auf dem zweiten oder dritten befand - das ist nicht schön .
Alle anderen Programme merken sich den Monitor auf dem sie zuletzt maximiert dargestellt wurden?
Selbst wenn ich den Monitor ermitteln könnte auf dem das Programm zuletzt angezeigt wurde, kann ich es nicht testen...
Ja, zumindest die welche ich öfters maximiert benutze. Es ist gar nicht nötig den Monitor zu ermitteln, da sich die Koordinaten über alle vorhandenen Bildschirme erstrecken. Es würde also reichen zusätzlich zu Form.WindowState noch Form.Left zu sichern und zu setzen - leider ist auf diese Weise die 'normale' Position des maximierten Formulars nicht wiederherstellbar, darum mache ich es in etwa so:

Delphi-Quellcode:
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;
Jeweils im OnCreate bzw. OnDestroy des Formulars eingebaut.

Grüße

Torsten
  Mit Zitat antworten Zitat