Autor Beitrag
jamany
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Do 29.05.03 13:27 
Ich möchte mein Programm beim Starten gleich in den Tray laden. Dazu verwende ich folgende Befehle:

ausblenden Delphi-Quelltext
1:
procedure applicationminimize(sender:TObject);					


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure tform1.applicationminimize;
Begin
  IconData.hicon:=application.icon.handle;
  IconData.cbSize:=SizeOf(TNotifyIconData);
  IconData.wnd:=handle;
  IconData.uid:=getcurrentprocessID;
  IconData.uFlags:=NIF_ICON + NIF_MESSAGE + NIF_TIP;
  IconData.uCallbackmessage:=$100;
  Shell_NotifyIcon(NIM_ADD,@IconData);
  showwindow(application.handle,sw_hide);
End;

In FormCreate habe ich dann
ausblenden Delphi-Quelltext
1:
application.OnMinimize:=applicationMinimize;					

Das funktioniert auch wunderbar. Ich würde es aber gerne so einrichten, dass das Programm automatisch in den Tray geladen wird, wenn ich das Programm starte. Wenn ich den Befehl
ausblenden Delphi-Quelltext
1:
Application.Minimize;					

einfüge, dann habe ich das Programm sowohl in der Taskleiste, als auch im Tray. Es wird nicht aus der Taskleiste entfernt. Was muss ich ändern?
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Do 29.05.03 17:43 
ausblenden Quelltext
1:
ShowWindow(Application.Handle, SW_HIDE);					

_________________
Life is a bad adventure, but the graphic is really good!
jamany Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Do 29.05.03 18:19 
Hab ich doch in meinem Code. Aber es funktioniert nur, wenn ich auf die Minimieren-Schaltfläche oben rechts klicke.
Nicht wenn ich das Program per Befehl minimiere.

Der Befehl steht in der Prozedur, aber es geht nicht...
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Do 29.05.03 18:34 
:oops: PMIGBOM

Jetzt verstehe ich. Ich denke, du solltest in der Projektdatei (also .DPR) nach "Application.CreateForm()" den Befehl "Application.ShowMainForm := False" einbauen. Dann ist das Form SOFORT unsichtbar. Dann musst du aber, wenn du das Form irgendwann mal anzeigen willst, "Application.ShowMainForm := True" angeben, sonst taucht dein Form nie auf!

_________________
Life is a bad adventure, but the graphic is really good!
jamany Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Do 29.05.03 21:37 
Also das mit dem verschwinden lassen funktioniert. Aber das wieder anzeigen geht nicht.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure tform1.iconmessage;
Begin
  application.restore;
  showwindow(application.handle,sw_normal);
  Shell_NotifyIcon(NIM_DELETE,@IconData);
  application.ShowMainForm:=True;
End;

Das Programm wird aus dem Tray genommen und in der Taskbar angezeigt. Das Programm selbst wird aber nicht angezeigt. Obwohl ich application.ShowMainForm auf True gesetzt habe.

Oder muss ich das an einer anderen Stelle machen?
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Fr 30.05.03 10:54 
An erster Stelle!

Und versuche folgende Codes:
ausblenden Delphi-Quelltext
1:
Form1.Show;					

oder
ausblenden Delphi-Quelltext
1:
Form1.Visible := True;					

oder
ausblenden Delphi-Quelltext
1:
Application.BringToFront;					


keien Ahnung, aber irgendiwe muss es ja funzen.

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.

_________________
Life is a bad adventure, but the graphic is really good!
jamany Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Sa 31.05.03 13:39 
ausblenden Quelltext
1:
Form1.Show;					

hat geklappt.

Jetzt wäre nur noch die Kleinigkeit, dass das Fenster dann auch im Vordergrund erscheinen soll.

Das Programm erscheint in der Taskbar und mit einem Klick darauf kommt es auch in den Vordergrund.

ausblenden Quelltext
1:
Application.BringToFront;					

bringt irgendwie nichts, außer dass dann das Programm in der Taskbar blinkt (aber leider nicht in den Vordergrund geholt wird...
Andreas Pfau
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 997



BeitragVerfasst: Sa 31.05.03 16:06 
Hallo,

ich habe grade ein altes Projekt gefunden, das das selbe macht (beim minimieren verschiwndet das TrayIcon, beim anclicken des Icons wird das Prog wieder normal angezeigt, das Taskbar-Icon erscheint wieder). Also, ich mache das so:
- Ein TApplicationEvents ruft bei OnMinimize fongeden Code auf:
ausblenden Quelltext
1:
ShowWindow(Application.Handle, SW_Hide);					

- Bei der TrayIcon-Mesage kommt dann folgendes:
ausblenden Quelltext
1:
2:
3:
4:
Application.ShowMainForm := True;
Main.Visible := True;
ShowWindow(Application.Handle, SW_Show);
Application.Restore;

- Der Selbe Code kommt auch beim ersten anzeigen, wenn ShowMainForm noch False ist
- Beim erstellen der Anwendung kommt:
ausblenden Quelltext
1:
Application.ShowMainForm := False;					


Versuch es so, dann müsste alles klappen.

_________________
Life is a bad adventure, but the graphic is really good!
jamany Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 73



BeitragVerfasst: Sa 31.05.03 19:23 
Tausend Dank. Klappt alles.