Autor Beitrag
Sanjo123
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 30.03.09 12:23 
Morgen :)

Wie kann ich es schaffen, dass sich mein Haupt-Formular nicht immer kurz öffnet, um zu prüfen, ob der Autostart-und-Verstecken-Parameter gesetzt ist um sich dann selbst zu verstecken (Form1.Hide) ?

Die Parameterabfrage mache ich mit einem Timer. Aber das führt dazu, dass das Hauptformular vor dem Verstecken je nach Prozessorleistung ein paar Sekunden noch offen ist, bis es sich selbst versteckt, was sehr unschön ist.

Wie kann ich das ändern ?

Bye Sanjo


Moderiert von user profile iconGausi: Topic aus Windows API verschoben am Mo 30.03.2009 um 12:33
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mo 30.03.09 12:32 
Hallo und :welcome: in der Entwickler-Ecke,

Das sollte über die Eigenschaft visible der Form gehen, die man dann halt im Objektinspektor auf False setzt.

_________________
We are, we were and will not be.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 30.03.09 12:43 
Ganz einfach :) Öffne den Quelltext deines Projektes (Projekt --> Quelltext anzeigen oder drücke F8, STRG+F2 und F12) und ändere deinen Source wie folgt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);

  if ParamCount > 0 then
    if ParamStr(0) = 'Autostart' then
      Application.ShowMainForm := False;

  Application.Run;
end.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Sanjo123 Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 30.03.09 14:30 
Das klappt nicht, selbst wenn ich die Einschränkung mit dem ParamStr() weglasse (und müsste es nicht ParamStr(1) heißen ?) ?? Die Form wird weiterhin angezeigt :(
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 30.03.09 14:34 
Nun, ParamStr(0) ist der Pfad zur Exe. Das gehört natürlich angepasst, also ja, in deinem Fall wahrscheinlich ParamStr(1). Wie rufst du denn die Exe genau auf, welche Parameter?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Sanjo123 Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 30.03.09 14:38 
Ich habe inzwischen rausgefunden, dass man Form1 auf Visible := False setzen muss, damit ShowMainForm überhaupt eine Auswirkung hat.

Ich habe nun ParamStr auf 1 gesetzt und checke, ob "-hide" oder "- hide" gesetzt sind:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  if ParamCount > 1 then
    if (ParamStr(1) = '-hide'or (ParamStr(1) = '- hide'then
      Application.ShowMainForm := False;
  Application.CreateForm(TForm2, Form2);
  Application.Run;
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 30.03.09 14:40 
ParamCount muss weiterhin auf 0 geprüft werden. Ohne Parameter (auch wenn ParamStr(0) der Pfad zur Exe ist), ist ParamCount = 0, ansonsten eben > 0. Und dann musst du auch nicht auf Visible := False; setzen, weil das wäre eine dauerhafte Versteckmethode :-P

Achso, eins noch: '- hide' wären zwei Parameter. Also wäre dafür eine Schleife geschickt:

ausblenden Delphi-Quelltext
1:
2:
3:
for X := 1 to ParamCount do
  if (ParamStr(X) = '-hide'OR (ParamStr(X) = 'hide'then
    ...


Oder, 3. Möglichkeit:

ausblenden Delphi-Quelltext
1:
2:
if Pos('hide', CmdLine) > 0 then
  ...

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Mo 30.03.09 14:46 
Ich hätte das so Persönlich so gemacht:

ausblenden Delphi-Quelltext
1:
2:
3:
 
    ShowWindow(Application.Handle, SW_HIDE);
    Form1.Visible := false;
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 30.03.09 14:51 
Anstatt das Auto erst gar nicht aus der Garage zu fahren, wirfst du lieber einen Tarnumhang drüber. Ach, ich liebe diese Autovergleiche :mrgreen:

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Mo 30.03.09 15:18 
Warum nicht einfach gleich Form1.Close ^^ Dann sind alle Probleme gelöst.
Und bei Showmainform := false; ist es meines erachtens auch nur Unsichtbar oder seh ich das falsch? ^^
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Mo 06.04.09 16:56 
Wenn die Form wirklich "WEG" sein soll und nicht unsichtbar dann:
ausblenden Delphi-Quelltext
1:
 FreeAndNil(Form1);