Autor Beitrag
FriFra
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 17:08 
Wie kann ich en fremdes Programm (ich habe das Handle) sauber beenden?
TerminateProcess killt ja nur die Anwendungen. Ich will aber erreichen, dass die Programme normal beendet werden.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 18:33 
ich glaub das geht so

ausblenden Quelltext
1:
PostMessage(FindWindow(nil,pchar('ANWENDUNGSNAME'),WM_CLOSE, 0, 0);					

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Mo 24.06.02 19:08 
Ansonsten mal WM_QUIT testen.

Es gibt aber auch noch andere, weitaus aufwendigere, Methoden.

Doch probiere erst mal die oben genannte.

Grüße

Torsten
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 20:59 
:cry: Es geht leider nicht...


Auf WM_CLOSE reagiert die Anwendung nicht und WM_QUIT beendet das Programm nicht sauber, sondern schiesst einfach nur den Task ab.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 21:05 
Was ist den "sauber" beenden.. wenn man den Task beendet wird die anwendung doch auch geschlossen :?:

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 21:13 
Task abschiessen ist kein sauberes Beenden, da die Applikation dann keine chance mehr hat zu reagieren! Die Anwendung soll so geschlossen werden, wie wenn man auf [X] klickt...
Die fremde Anwendung soll "merken", dass sie beendet wird...


Zuletzt bearbeitet von FriFra am Mo 24.06.02 21:14, insgesamt 1-mal bearbeitet
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Mo 24.06.02 21:13 
Hast Du das andere Programm mit CreateProcess gestartet?
Oder ist es eine völlig fremde Anwendung?

Grüße

Torsten
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 21:16 
Ich habe das Programm mit CreateProcess gestartet, deshalb habe ich auch das Processhandle :wink:
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 21:18 
du kannst ja noch

WM_Destroy
WM_Endsession

probieren

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 21:19 
oder schau mal in der Delphi-Hilfe nach ob du was findest

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Mo 24.06.02 21:22 
Ah ja, sorry. Hatte ich überlesen.

OK, dann hätte ich noch eine andere Variante.

Da Du ja das Programm selber geschrieben hast, müsstest Du ja auch die Klassennamen kennen.
Somit gehe doch den direkten Weg:

ausblenden Quelltext
1:
2:
if(findwindow(pchar('TMyForm'),nil) <> 0) then 
  SendMessage(findwindow(pchar('TMyForm'),nil),WM_CLOSE,0,0);


Dabei gibt es lediglich ein Problem.
Nämlich, wenn Du alle Programme mit Formularnamen TMyForm nutzt.

Grüße

Torsten[/code]
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 21:29 
Wie schon gesagt, auf WM_CLOSE reagiert das Programm nicht und WM_QUIT ist das gleiche wie TerminateProcess...

Es scheint ja keiner eine echte Lösung zu haben... Ich muss aber das Programm richtig beenden, da es sein Trayicon OnClose bzw. OnDestroy selbst entfernt und ich keine Metode kenne verweiste Trayicons zu entfernen ohne mit der Maus drüber zu fahren...
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Mo 24.06.02 21:33 
Auch die letzte Lösung funzt nicht?
Komisch.

Na ich schau mich noch mal um.

Grüße

Torsten
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 21:33 
also wen ich ein programm was ein tray-icon besitzt abschiese (prozess bzw. task beende) dann is auch das tray-icon weg...

wenn du die tray-icon-anwendung im form OnDestroy die "icon-löschen-funktion" reinmachst müsste es auch funktionieren

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 21:36 
Es funzt aber nicht... OnDestroy wird das Icon entfernt, das klappt auch beim normalen beenden, wenn ich aber den Task abschiesse bleibt das Icon... beim drüberfahren mit der Maus verschwindet es...
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 21:39 
dan kanst dus nur noch mit DLLs versuchen die beide programme nutzen, da hört mein wissen aber auf

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 21:46 
Es müsste ja auch gehen, wenn man dem Tray eine Message sendet, damit er sich aktualisiert...
Torsten
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 160



BeitragVerfasst: Mo 24.06.02 21:47 
Moinsen!

OK, noch mal zum Verständniss.
Die Anwendung, die beendet werden soll, ist auch von Dir geschrieben! Richtig?

Wenn dem so ist, dann kannst Du in das Programm, welches beendet werden soll, einen MessageHandler einbauen.

Beispiel:

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
private
  procedure MyMsgHandler(var: msg: TMsg; var Handled: Boolean);
public

...

procedure TForm1.FormCreate(Sender: TObject);
begin
   Application.OnMessage:= MyMsgHandler;
end;

...

procedure MyMsgHandler(var: msg: TMsg; var Handled: Boolean);
begin
   if msg.Message = WM_IRGENDWAS then
  ...
end;


Sollte funktionieren. Habe aber jetzt gerade nicht getestet.

Grüße

Torsten
FriFra Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 557

Win XP Prof, Win XP Home,Win Server 2003,Win 98SE,Win 2000,Win NT4,Win 3.11,Suse Linux 7.3 Prof,Suse Linux 8.0 Prof
D2k5 Prof, D7 Prof, D5 Standard, D3 Prof, K3 Prof
BeitragVerfasst: Mo 24.06.02 21:55 
Das aktuelle Programm ist von mir, aber die eigentliche Anwendung soll universell einsetzbar sein. Und das Problem mit den verwaisten Trayicons besteht bei alle Programmen welche im Tray laufen... deshalb wäre mir eine Lösung lieber, die entweder das Programm richtig schliesst oder aber den Systray repaintet...
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Mo 24.06.02 21:59 
komisch, also wenn ich z.B. icq abschiese dann ist das rtray-icon auhc mit weg.. aber du kannst ja kurzzeitig die taskleiste verstecken und wieder einlbenden

var hTaskBar: THandle;

Taskleiste verstecken:

ausblenden Quelltext
1:
hTaskbar:=FindWindow('Shell_TrayWnd',nil); ShowWindow(hTaskBar, SW_HIDE);					


Taskleiste sichbar machen:

ausblenden Quelltext
1:
hTaskBar:=FindWindow('Shell_TrayWnd', nil); ShowWindow(hTaskBar, SW_SHOWNORMAL);					

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce