Autor Beitrag
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 30.09.02 21:07 
Hallo !!!

Ich habe aus folgender Post www.auq.de/viewtopic.php?t=2145 den Code von MathiasSimmack in mein Proggi eingebaut (Danke nochmal an dieser Stelle !!!).
Hier nochmal der Code:
ausblenden 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:
var 
  WebBrowsersOnly : boolean = false; 

function CloseAll(Wnd: hWnd; lparam: LPARAM): longbool; stdcall; 
const 
  browser_classes : string = 'IEFrame|MozillaWindowClass|BLDOPERA'; 
var 
  buf : array[0..MAX_PATH - 1]of char; 
begin 
  if(WebBrowsersOnly) then GetClassName(Wnd,buf,80); 

  if(not(WebBrowsersOnly)) or (pos(buf,browser_classes) <> 0) then 
    begin 
      if((GetWindowLong(Wnd, GWL_STYLE) and (WS_VISIBLE or WS_SYSMENU)) = 
        (WS_VISIBLE or WS_SYSMENU)) then 
      PostMessage(Wnd, WM_SYSCOMMAND,lParam,0); 
    end; 

  Result := true; 
end; 


{ ... } 

begin 
  WebBrowsersOnly := true; 
  EnumWindows(@CloseAll,SC_CLOSE); 
end;


Dieser Code schliesst, wenn die Variable WebBrowserOnly auf true steht alle Browserfenster. Wenn sie auf false steht, werden alle aktiven Fenster geschlossen. Soweit klappt alles !!!

Ich wollte aber ausserdem noch, dass MEIN proggi, egal was passiert immer ausgelassen wird, sprich: offen bleicbt auch wenn alle anderen Fenster geschlossen werden (webbrowseronly := false).
Dazu hat MathiasSimmack folgenden Code gepostet:

ausblenden Quelltext
1:
2:
Browserfenster 
  if(not(WebBrowsersOnly)) or (pos(buf,browser_classes) <> 0) and (not(buf = 'TForm1') then


Was leider nicht funzt.

Ich habe dann (wieder mit Hilfe von MathiasSimmack) das folgendermassen umgeändert:

ausblenden Quelltext
1:
2:
if((not(WebBrowsersOnly)) or (pos(buf,browser_classes) <> 0)) and 
  ((Wnd <> Form1.Handle) AND (Wnd <> Application.Handle)) then


Das funzt aber auch nicht
Kann mir bitte jemand sagen warum !!!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 30.09.02 21:21 
Also noch mal, matze.
Ich habe hier jetzt mal einen Code zum Ausprobieren für dich:
ausblenden 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:
var
  WebBrowsersOnly : boolean = false;

function CloseAll(Wnd: hWnd; lparam: LPARAM): longbool; stdcall;
const
  browser_classes : string = 'IEFrame|MozillaWindowClass|BLDOPERA';
var
  buf : array[0..MAX_PATH - 1]of char;
begin
  //if(WebBrowsersOnly) then
  GetClassName(Wnd,buf,80);

  if((not(WebBrowsersOnly)) or (pos(buf,browser_classes) <> 0))
  then
    begin
      if((GetWindowLong(Wnd, GWL_STYLE) and (WS_VISIBLE or WS_SYSMENU)) =
        (WS_VISIBLE or WS_SYSMENU)) then
      ShowMessage(buf);

//      PostMessage(Wnd, WM_SYSCOMMAND,lParam,0);
    end;

  Result := true;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  EnumWindows(@CloseAll,SC_CLOSE);
end;

Button auf die Form, Code rein und ausprobieren.

Die Kommentare sind absichtlich drin. Schließlich wollte ich meinen offenen Mozilla nicht schließen. :) Ich lasse mir also nur die Klassennamen anzeigen, und ich sehe neben anderen Fenstern auch "TForm1" und "TApplication" - die in dem Fall zu meiner Anwendung gehören.
Wie deine Form heißt, weiß ich nicht, aber zumindest bis hier sollte es auch bei dir funktionieren.

Wenn du die Bedingungsprüfung jetzt mal so änderst:
ausblenden Quelltext
1:
2:
if((not(WebBrowsersOnly)) or (pos(buf,browser_classes) <> 0)) and
  ((Wnd <> Form1.Handle) and (Wnd <> Application.Handle))

dann siehst du nur noch die Klassennamen der anderen Fenster. Der Name deiner Form und das dazu gehörende (!) "TApplication"-Fenster tauchen nicht mehr auf.

Wenn du jetzt das ShowMessage entfernst und stattdessen wieder die "PostMessage"-Anweisung aktivierst, dann werden alle Programme beendet - nur eben deins nicht.

Bei mir geht es also.
Es wäre aber hilfreich, wenn du sagst, was bei dir nicht klappt.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 01.10.02 11:54 
:dance: :dance: Hosaa, holldrio, super, jubel, heiterkeit :dance: :dance: usw...

Es KLAPPT !!!!!!

Jetzt würde mich nur mal interessieren: warum klappt das jetzt und das alte nicht :?!?: :nixweiss:

Und noch ne Frage: Wie muss ich den Code umbauen, wenn ich das fenster killen statt schliessen will ??
das geht doch irgendwie über TerminateProcess oder ???

_________________
In the beginning was the word.
And the word was content-type: text/plain.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 03.10.02 17:48 
kann mir jemadn sagen, wie ich die Fensterklassen für word usw... rausbekomme ??

_________________
In the beginning was the word.
And the word was content-type: text/plain.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 03.10.02 18:44 
@matze: entweder mit den Tools Spy++ [Microsoft], WinSight [Borland] oder aber dem X-Spy [ich :mrgreen:] Link für den X-Spy: motzi.fs-tools.de (gibt auch einen Thread unter Freeware wo man Kommentare, Bug-Reports, etc. loswerden kann)

(03.10.02 20:16 Tino) Signatur entfernt. Siehe Richtlinien.
matze Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 03.10.02 18:57 
danke

_________________
In the beginning was the word.
And the word was content-type: text/plain.