Autor Beitrag
Airwolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Sa 25.10.08 19:52 
Hi Leut's,

hab mal ne Frage. Ich will, wenn mein Programm läuft und ich auf das X oben im Fenster klicke, dass es dann nit beendet wird, sondern nur minimiert, quasi in den Tray minimiert wird. Wie mach ich das?

Danke im voraus
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Sa 25.10.08 20:02 
Es gibt das OnClosing-Ereignis beim Formular, da setzt du dann einfach die CanClose-Eigenschaft des Parameters auf False. Dann kannst z.b. WindowState auf wsMinimized setzen. Bin mir nicht ganz sicher, aber ziemlich. :P
Xentar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2077
Erhaltene Danke: 2

Win XP
Delphi 5 Ent., Delphi 2007 Prof
BeitragVerfasst: Sa 25.10.08 20:04 
Das Ereignis heißt OnCloseQuery :P

_________________
PROGRAMMER: A device for converting coffee into software.
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Sa 25.10.08 20:58 
OK, jetzt bin ich am verzweifeln. Habe irgendwas rumprobiert und meiner Meinung nach auch rückgängig gemacht und nu funktionierts nit mehr so wies soll. An einem Punkt hatte es mal so funktioniert wie es sollte, d.h. ich konnte es so oft schließen und wieder aufrufen, konnte so oft wie ich wollte progrmme damit starten und es schließen und wieder öffnen, aber jetzt nicht mehr.

Also mal zusammengefasst: Programmstart: Pause(fenster sichtbar machen) und Enter(Eingabe bestätigen) funktionieren ==> Programm starten ==> funktioniert ==> Programm sichtbar machen ==> funktioniert ==> Programmstarten ==> funktioniert nicht mehr, Enter ist scheinbar nit mehr deklariert ==> Programm minimieren wollen (über das X im Fenster) ==> Programm wird beendet aber nit minimiert wies sein sollte.

Hoffe das war verständlich...

Ich poste mal meinen Quelltext, vllt. fällt euch was auf was ich übersehen habe. Muss irgendwie was schieflaufen mit der Hotkeyregistrierung

ausblenden volle Höhe Delphi-Quelltext
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:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellAPI;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    
  private
    { Private declarations }

  procedure WmHotkey(var Msg: TMessage); message WM_HOTKEY;  
  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



procedure TForm1.FormCreate(Sender: TObject);
  begin
    RegisterHotKey(Handle, 1,0,VK_Return);
    RegisterHotKey(Handle, 2,0,VK_Pause);
    
  end;

//=================================================================

procedure TForm1.WmHotkey(var Msg: TMessage);
  var Programmname : string;
      ID : integer;
  begin
    if (Msg.WParam = 2) then form1.visible:=true;

    
    if (Msg.WParam = 1) then
      begin
      //--------------------------------------------------------------------------------------------------
      Programmname:= Edit1.Text;
      //--------------------------------------------------------------------------------------------------
    ==>macht sachen<== (zensiert)
    form1.Visible:=false;
    UnregisterHotKey(handle,1);
    edit1.Text:='';

  end;

end;

//===============================================================================

procedure TForm1.FormActivate(Sender: TObject);
begin
RegisterHotKey(Handle, 1,0,VK_Return);
end;

//================================================================================

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose:=false;
form1.visible:=false;
end;

end.


Das zensierte geht niemanden was an, da stehen ne ganze Menge Programme die ich aufm rechner habe. Da gehts nur drum dass die geöffnet werden, kann aber keinesfalls Einfluss auf das Problem nehmen, nur nen paar Variablenzuweisungen und Shellexecute in ner Case of anweisung.

Es hat so eigentlich schonml funktioniert, aber scheinbar habe ich doch was übersehen...

Danke nochmal und im voraus

Moderiert von user profile iconNarses: Code- durch Delphi-Tags ersetzt
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 25.10.08 21:31 
Im Hotkey-Event deregistriert Du den Hotkey wieder und wunderst Dich, dass der nur einmal tut?
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Sa 25.10.08 21:55 
Hab den Fehler gefunden. Den Hotkey für Enter musste ich deaktivieren weil ich sonst im normalen Betrieb wenn das Programm versteckt war Enter nicht benutzen konnte, war dann nur für das Prog reserviert. Hatte mich aber darauf versteift dass Onactivate das wieder aktiviert, hatte ich ja reingeschrieben dass da der Hotkey wieder registriert werden soll, hats aber nit. Hab aber rausgefunden dass das Onshow kann.

jetzt klappt das mit den Hotkeys wieder, aber das minimieren des Programm wenn ich aufs x klicke funktioniert nit. Das Prog wird ganz normal beendet und nit geschlossen

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

OK, habe auch das Problem gelöst: Windows Fehlerbehebung...

Habe die ganze Prozedur gelöscht und den Eintrag bei den Types oben rausgenommen, dann nochmal hinzugefügt und jetzt klappts...

Schien die Prozedur irgendwie nit mehr im system registriert gewesen zu sein oder wie darf ich das verstehen?
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Mo 27.10.08 14:55 
OK, funktioniert alles soweit wie es funktionieren soll. Allerdings ist mir was aufgefallen, was bestimmt mit dem canClose:=false; zusammenhängt, wenn das Programm läuft kann ich Windows nicht mehr herunterfahren, reagiert einfach nit. Sobald ich mein Programm beende lässt es sich ganz problemlos herunterfahren. Wie kann ich das beheben?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.10.08 15:05 
Reagiere auf WM_QUERYENDSESSION, indem Du ein privates Feld oder eine Variable setzt und dies beim Setzen von CanClose berücksichtigst.
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Mo 27.10.08 15:10 
Hab ich das richtig verstanden?
Bei private irgendwas mit WM_QUERYENDSESSION hinschreiben und drunter ne bool'sche variable setzen die ich dann statt dem false bei canClos:=false; die variable hintue?
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.10.08 15:15 
Ich meinte das in etwa so:
ausblenden Delphi-Quelltext
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:
type 
  TFormBlubb = class(TForm)
    ...
  private 
    FExitWindows: Boolean;
    procedure WMQueryEndSession(var Msg: TWMQueryEndSession);
      message WM_QUERYENDSESSION;
  ...
  end;

...

procedure TFormBlubb.WMQueryEndSession(var Msg: TWMQueryEndSession);
begin
  FExitWindows := true;
  Msg.Result := Word(true);
end;

procedure TFormBlubb.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
  if FExitWindows then
    CanClose := true
  else
    begin
      //Dein jetziger Code  
    end;
end;


Ohne Gewähr, da aus dem Kopf getippt.
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Mo 27.10.08 15:45 
Hmm, obwohl ich FExitWindows im private deklariert habe, meint er ich hätte das nicht. Er meint dann immer:
[Error] Unit1.pas(37): Undeclared identifier: 'FExitWindows'

Weiterhin scheint er die WMQueryEndSession auch nit zu kennen, da kommt dann

[Error] Unit1.pas(21): Unsatisfied forward or external declaration: 'TForm1.WMQueryEndSession'

In der Hilfe finde ich auch nix unter ner WMQueryEndSession
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.10.08 16:01 
Zeig mal den Code.
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Mo 27.10.08 16:05 
ausblenden volle Höhe Delphi-Quelltext
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:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ShellAPI, IniFiles;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure WMQueryEndSession(var Msg: TWMQueryEndSession);
  private
    { Private declarations }
  FExitWindows: Boolean;

  procedure WMQueryEndSession(var Msg: TWMQueryEndSession); message WM_QueryENDSESSION;
  procedure WmHotkey(var Msg: TMessage); message WM_HOTKEY;
  public
    { Public declarations }

  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure WMQueryEndSession(var Msg: TWMQueryEndSession);
  begin
  FExitWindows:= true;
  Msg.Result := Word(true);
  end;

procedure TForm1.FormCreate(Sender: TObject);
  begin
    RegisterHotKey(Handle, 1,0,VK_Return);
    RegisterHotKey(Handle, 2,0,VK_Pause);
    
  end;

procedure TForm1.WmHotkey(var Msg: TMessage);
  var ini:TIniFile;
      name:string;
      pfad:string;

  begin
  //if (Msg.WParam = 2) then form1.visible:=true;
  if (Msg.WParam = 1) then
  begin
  name:=edit1.Text;
  ini:= TIniFile.Create('F:\Meine Dateien\Setups und Pätsches\Delphi\EasyStart v1.1\paths.ini');

  try
  pfad:=ini.Readstring('paths', name, '');
  ShellExecute(0, 'open',PChar(pfad),nil,nil, SW_SHOW);
  finally
  ini.Free


  end;
  end;
  end;

procedure TForm1.FormActivate(Sender: TObject);
begin
RegisterHotKey(Handle, 1,0,VK_Return);
end;


procedure TForm1.FormShow(Sender: TObject);
begin
RegisterHotKey(handle, 1, 0, VK_Return);
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if FExitWindows=true then CanClose:=true
                     else
                     begin
                     canclose:=false;
                     form1.visible:=false;
                     end;
end;


end.


Außerdem sagt er mir noch sowas:
[Error] Unit1.pas(21): Overloaded procedure 'WMQueryEndSession' must be marked with the 'overload' directive

Kam jetzt nachdem ich die WMQueryEndSession bei den Types noch eingefügt hatte, hatte ich vergessen, resultat bleibt aber das gleiche.

Moderiert von user profile iconGausi: Code- durch Delphi-Tags ersetzt


Zuletzt bearbeitet von Airwolf am Mo 27.10.08 16:12, insgesamt 1-mal bearbeitet
DeddyH
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 27.10.08 16:10 
Du hast WMQueryEndSession 2 mal deklariert. Die Zeile vor "private" muss weg. Außerdem ist das eine Methode von Form1, im implementation-Abschnitt muss es also Form1.WMQueryEndSession heißen.
Airwolf Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 92



BeitragVerfasst: Mo 27.10.08 16:16 
OK, scheint zu funktionieren