Autor Beitrag
Crowbar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Sa 18.03.06 17:55 
Hi,
je nachdem wie mein Programm beendet wird (im maximierten oder im normalen Fenster-Zustand), soll es auch wieder gestartet werden.
Wird jedoch das Programm im max. Form (WindowState:=wsMaximized) gestartet, kann ich über den Fenster-Button "Verkleinern" mein Programm nicht mehr in meine normale Fenstergröße bringen. Es bleibt einfach "maximiert"! :cry:
Über die DF-Suche habe ich ein Stichwort "GetWindowPlacement" gefunden. Diese Funktion soll den Status "fsNormal" des Fensters zurückgeben.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Procedure TForm1.FormCreate(Sender: TObject);
var
 wp: TWindowPlacement;

begin
  wp.length:= SizeOf(wp);
  GetWindowPlacement(Handle,@wp);
  WindowState:=wsMaximized;
...
end;

:roll: Wie setze ich den Code richtig ein, um auch nach dem maximierten Fenster-Zustand wieder in die normale Fenstergröße zurückzukommem (per Fenster-Button "Verkleinern")? :roll:

Gruß
Crowbar
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 18.03.06 18:02 
Andere Vorschlag:
Wie groß ist denn die "normale" Größe?
Du könntest im Ereignis OnRestore diese Größe wiederherstellen (form1.width und form1.height)
Benutze dazu die Komponente ApplicationEvents unter Zusätzliches.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Crowbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Sa 18.03.06 18:08 
Hi Marco,
die "Standardgröße", also wsNormal, ist:
Breite = 780 und Höhe = 560
Im OI habe ich für meine TForm kein "OnRestore" - Ereignis finden können. :?:

Gruß
Crowbar
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Sa 18.03.06 18:22 
user profile iconCrowbar hat folgendes geschrieben:
Im OI habe ich für meine TForm kein "OnRestore" - Ereignis finden können. :?:

Dann lies mal oben :mahn: :
user profile iconMarco D. hat folgendes geschrieben:
Benutze dazu die Komponente ApplicationEvents unter Zusätzliches

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 18.03.06 18:29 
Hatte dieselbe Frage vor kurzem auch, und auch eine Antwort bekommen: klick.

Beim Speichern der Werte beim Beenden halt diese Werte nehmen (nicht Form1.width etc.), die dann beim Start setzen, und ggf. den Style auf WsMaximized setzen, falls die Form maximiert war (oder halt nicht). Ein Klick auf den "normal/max-Button" in der Titelleiste verkleinert die Form dann richtig.

_________________
We are, we were and will not be.
Crowbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Sa 18.03.06 18:30 
Ups, habe ich ganz überlesen. :oops:
Natürlich hat TApplication ein "onRestore" - Ereignis.
Ich teste es mit der Komponente ApplicationEvents.

Gruß
Crowbar
Crowbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Sa 18.03.06 18:37 
@ Gausi:
Danke für Deinen Link.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var PosAndSize : PWindowPlacement;
    L,T,R,B : Integer;
begin
  GetMem(PosAndSize,SizeOf(TWindowPlacement));
  try
     PosAndSize^.Length := SizeOf(TWindowPlacement);
     if GetWindowPlacement(Handle,PosAndSize) then begin
        L := PosAndSize^.rcNormalPosition.Left;
        T := PosAndSize^.rcNormalPosition.Top;
        R := PosAndSize^.rcNormalPosition.Right;
        B := PosAndSize^.rcNormalPosition.Bottom;
        end;
    showmessage(IntToStr(L));
    //...
  finally
     FreeMem(PosAndSize,SizeOf(TWindowPlacement))
  end

Aber wo genau hast Du diesen Code benutzt? Im Form.Create - Ereignis?

Gruß
Crowbar
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8554
Erhaltene Danke: 481

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Sa 18.03.06 18:47 
Ich habe dich so verstanden, dass du deine Form so wiederherstellen willst, wie du sie beim letzten programmstart hattest. Dazu musst du die Werte (Position und Größe) beim Beenden des Programms speichern (z.B. in einer Ini-Datei), und beim Start wieder laden.

Das Stück Code liefert die Größe der "nicht-maximierten Form" zurück, die ich im OnClose (oder wars OnDestroy?) speichere, um sie beim nächsten create wieder zu laden und zu setzen.

_________________
We are, we were and will not be.
Crowbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Sa 18.03.06 18:58 
@Gausi:
Jetzt hat es bei mir "Klick" gemacht. :think:
Ja, natürlich, dass wäre ein besserer Weg, um sich das Ganze mit dem wsMaximized usw. zu sparen.
Danke Gausi für Deinen "Gedankenanstoss"! :)

Gruß
Crowbar
Crowbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 180

WinXP, SP2
D6 Enterprise
BeitragVerfasst: Sa 18.03.06 20:50 
Ich bin es doch noch einmal.
Den Code von Gausi's Link habe ich in meinem Programm eingearbeitet. Er funktioniert auch wunderbar und speichert bzw. lädt die letzten Fenstergröße bzw. -position.
Nur ist jetzt ein kleines Problem aufgetreten:
Wenn ich meine Form maximiere, anschliessend beende und wieder starte, speichert bzw. lädt er die richtige Position (Left = 0 und Top = 0). Jedoch "hupft" das Fenster automatisch um 15 Pixel nach unten (Left = 0 und Top = 15).
Dies hat sicherlich irgendetwas mit der Taskleiste zu tuen. Wie verhindere ich dies?
Mein Fenster soll, so wie die Position auch gespeichert wurde, bei Top = 0 angezeigt werden.

Ich bin alle Form.Position Einstellungen im OI durchgegangen ... leider stets der gleiche Effekt.

Gruß
Crowbar