Autor Beitrag
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 02.04.07 22:32 
Okay, jetzt ist es wiedermal soweit ;) Poste deine ganze Unit oder lad sie hoch.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Mo 02.04.07 22:35 
VIELEN DANK :flehan:
^^

Mindforce
Einloggen, um Attachments anzusehen!
_________________
Our force; in mind.
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 02.04.07 22:41 
So, ich hab gehighlightet / kommentiert wenn ich was geändert habe.


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:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
unit killerpas;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TLHelp32, StdCtrls, XPMan, ExtCtrls, Menus, TrayIcon;

type
  TMainWindow = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    ja: TButton;
    nein: TButton;
    Label8: TLabel;
    Image1: TImage;
    Image2: TImage;
    yn: TEdit;
    TI: TTrayIcon;
    PopupMenu1: TPopupMenu;
    Aboutbutt: TMenuItem;
    N1: TMenuItem;
    Beenden1: TMenuItem;
    Edit1: TEdit;
    Einstellungen1: TMenuItem;
    Opt1: TMenuItem;
    Opt2: TMenuItem;
    Button1: TButton;
    Button2: TButton;
    etmnsz1: TMenuItem;
    Apps: TListBox;
    Button3: TButton;
    Button4: TButton;
    Timer1: TTimer;

    procedure Timer1Timer(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure etmnsz1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Opt2Click(Sender: TObject);
    procedure Beenden1Click(Sender: TObject);
    procedure Opt1Click(Sender: TObject);
    procedure AboutbuttClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormCreate(Sender: TObject);
    procedure neinClick(Sender: TObject);
    procedure jaClick(Sender: TObject);

  private
   function KillTask(const AExeName: string): boolean;
   function GetUsername: String; { Private-Deklarationen }
   {MWMWMWMWMWMWMWMWMWMWMW}
   {MWMWMWMWMWMWMWMWMWMWMW}
   function FindAWindow(WinCaption: string; WinClassName: string): THandle;
   //Ich hab den Forward der EnumWindowProc Funktion rausgenommen
  public

{ Public-Deklarationen }
  end;

var
  MainWindow: TMainWindow;
  CapBuf:array[0..2047]of char;

  type

  PFindWindowStruct = ^TFindWindowStruct;
  TFindWindowStruct = record
    Caption: string;
    ClassName: String;
    WindowHandle: THandle;
end;

implementation

uses protpas, aboutpas;

{$R *.dfm}




function TMainWindow.GetUsername: String;
var
  Buffer: array[0..255] of Char;
  Size: DWord;
begin
  Size := SizeOf(Buffer);
  if not Windows.GetUserName(Buffer, Size) then
    RaiseLastOSError; 
  SetString(Result, Buffer, Size - 1);
end;

function TMainWindow.KillTask(const AExeName: string): boolean;
var
  p: TProcessEntry32;
  h: THandle;
begin
  Result := false;
  p.dwSize := SizeOf(p);
  h := CreateToolHelp32Snapshot(TH32CS_SnapProcess, 0);
  try
    if Process32First(h, p) then
      repeat
        if AnsiLowerCase(p.szExeFile) = AnsiLowerCase(AExeName) then
          Result := TerminateProcess(OpenProcess(Process_Terminate,
                                                 false,
                                                 p.th32ProcessID),
                                     0);
      until (not Process32Next(h, p)) or Result;
  finally
    CloseHandle(h);
  end;
end;


procedure TMainWindow.jaClick(Sender: TObject);
var sl: TStringList;
begin
yn.Text:='Yes';
if not KillTask('xD') then
    Showmessage('Das Programm konnte nicht beendet werden. Es ist wahrscheinlich ein System- Programm.');

    Form1.show;

MainWindow.Visible:=false;
edit1.Text:='mkay';
end;

procedure TMainWindow.neinClick(Sender: TObject);
begin
yn.text:='no';
MainWindow.Visible:=false;
Form1.Show;
edit1.Text:='mkay';

end;


procedure TMainWindow.FormCreate(Sender: TObject);
begin
Application.ShowMainForm:= false;
TI.Show;
Opt1.Checked:=true;
//enumwindows(@MainWindow,0);
end;

procedure TMainWindow.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose:=false;
if edit1.text = 'mkay' then CanClose:=true else
CanClose:=false;
end;

procedure TMainWindow.AboutbuttClick(Sender: TObject);
begin
About1.Show;
end;

procedure TMainWindow.Opt1Click(Sender: TObject);
begin
 if Opt1.Checked = true then Button3.Click else
 if Opt1.Checked = false then Button4.Click else
 showmessage('Fehler!');

end;

procedure TMainWindow.Beenden1Click(Sender: TObject);
begin
  if MessageDlg('Möchen Sie "closeR" wirklich beenden?',
              mtWarning,
              [mbYes,mbNo],0) = mrYes then if MainWindow.Visible = false then button2.click else if MainWindow.Visible = true then

              MessageDlg('Es ist noch eine Frage zu beantworten bis Sie dieses Programm beenden können!',
              mtERROR,
              [mbOk],0);





end;

procedure TMainWindow.Opt2Click(Sender: TObject);
begin

 if MessageDlg('Diese Funktion ist in der BETA noch nicht vorhanden! TD = /x001%xOpt2\',
              mtError,
              [mbOk],0) = mrOk then {NÖÖÖX};

 if Opt2.Checked = true then Opt2.Checked := false
 else
 if Opt2.Checked = false then Opt2.Checked := true;

 if Opt2.Checked = true then {Aktivieren}
 else
 if Opt2.Checked = false then {Deaktivieren} ;
end;

procedure TMainWindow.Button1Click(Sender: TObject);
begin
self.Visible:=false;
end;

procedure TMainWindow.Button2Click(Sender: TObject);
begin
edit1.Text:= 'mkay'; application.Terminate;
end;

procedure TMainWindow.etmnsz1Click(Sender: TObject);
begin
self.Visible:=true;
end;

procedure TMainWindow.Button3Click(Sender: TObject);
begin
Opt1.Checked := false;
TI.Hide;
end;

procedure TMainWindow.Button4Click(Sender: TObject);
begin
Opt1.Checked := true;
TI.Show;
end;

function EnumWindowsProc(wHandle: HWND; lb: TListBox): Bool; stdcall; export; //Forward rausgenommen
var
  Title, ClassName: array[0..255] of char;
begin
  Result := True;
  GetWindowText(wHandle, Title, 255);
  GetClassName(wHandle, ClassName, 255);
  if IsWindowVisible(wHandle) then
     lb.Items.Add(string(Title) + '-' + string(ClassName)); //Von Apps auf LB geändert
end;

procedure TMainWindow.Timer1Timer(Sender: TObject);
begin
 apps.items.clear; //die Listbox muss davor gelöscht werden
 EnumWindows(@EnumWindowsProc, Integer(Apps));
end;



function TMainWindow.FindAWindow(WinCaption: string; WinClassName: string): THandle;
var WindowInfo: TFindWindowStruct;
begin
  with WindowInfo do begin
    caption := WinCaption;
    className := WinClassName;
    WindowHandle := 0;
//    EnumWindows(@EnumWindowsProc, LongInt(@WindowInfo));
    result := WindowHandle;
  end;
  end;


end.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Mo 02.04.07 22:44 
Ich sag doch ich habn Brett vorm Kopf. Funktioniert endlich.

Thx.

Mindforce

_________________
Our force; in mind.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Mo 02.04.07 22:47 
Leer...

_________________
Our force; in mind.


Zuletzt bearbeitet von Mindforce am Di 03.04.07 12:19, insgesamt 1-mal bearbeitet
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mo 02.04.07 22:49 
Jo echt jetzt.

Das nächste mal wenn du so ein paar PRoblem hast würd ich einfach mal durchatmen und ne kurze Pause machen (eine Rauchen, was Trinken oder sonst was).

Das hatte grad nichts mit Wissen zu tun sondern mit reiner Konzentration. Das war wirklich reines Copy & Paste.


@edit: Im Normalfall solltest du einfach suchen oder ein neues Topic eröffnen: Nimm ne For-Schleife von 0 bis Items.count-1 und durchsuch die einzelnen Items mit pos.


edit2: Stimmt ja, das gehörte ja zur Ausgangsfrage im ersten Post :) Kann also doch hier drin bleiben denk ich mal.
Mindforce Threadstarter
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 358

Win XP Pro / MCE, Win 98, Slax (Linux)
Delphi 07 PRO, Delphi 3+7 (mit Prdx)
BeitragVerfasst: Di 03.04.07 12:19 
Hat sich schon erledigt. Hab slebst nen Code geschreiben. Bin leider faul

THX Karlson und andere die mir noch geholfen haben.

Mindforce

_________________
Our force; in mind.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 03.04.07 13:22 
Die EnumWindowsProc darf keine Methode deiner Klasse sein, da Methoden immer als ersten parameter die unsichtbare Self Variable mitübergeben wird und somit stimmt die Parameterliste nicht mehr. Aber das wurde dir doch schon ein paar mal in diesem Thread gezeigt an Hand von Quellcode.