unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,TlHelp32;
type
TForm1 =
class(TForm)
Button1: TButton;
Button2: TButton;
ListBox1: TListBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
type
EnumWindowsProc =
function (Hwnd: THandle;Param: Pointer): Boolean;
stdcall;
function GetWindowExeName(
Handle: THandle):
String;
var
PE: TProcessEntry32;
Snap: THandle;
ProcessId: cardinal;
begin
GetWindowThreadProcessId(
Handle,@ProcessId);
Snap:= CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if Snap <> 0
then begin
if Process32First(Snap,
PE)
then
if PE.th32ProcessID = ProcessId
then
Result:=
String(
PE.szExeFile)
else while Process32Next(Snap,
PE)
do
if PE.th32ProcessID = ProcessId
then begin
Result:=
String(
PE.szExeFile);
break;
end;
CloseHandle(Snap);
end;
end;
function GetTitle (Hwnd: THandle; Param: Pointer): Boolean;
stdcall;
var
Text,TempString:
string;
begin
If (GetWindowLong(Hwnd,GWL_HWNDPARENT)=0)
and (IsWindowVisible(Hwnd)
or IsIconic(Hwnd))
then
begin
TempString := GetWindowExeName(Hwnd);
SetLength (Text, 100);
GetWindowText (Hwnd, PChar (Text), 100);
Form1.ListBox1.Items.Add (IntToStr (Hwnd) + '
: ' + TempString + '
: ' +text);
Result := True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
EWProc: EnumWindowsProc;
begin
ListBox1.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
wnd :Hwnd;
temp :
string;
EWProc: EnumWindowsProc;
ClickedOK : boolean;
begin
clickedOK := InputQuery('
Which Process do U wanna Kill','
Process Number',temp);
if ClickedOK
then
begin
Wnd := hwnd(strToInt(temp));
PostMessage(Wnd,WM_SYSCOMMAND,SC_CLOSE, 0);
sleep(100);
ListBox1.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
end;
end;
end.