SwOoPe
asked on
List Active Programms
How do I list ALL active programs runing, visible and invisible? how can I close, hide, show focus a certine program?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It seems like your sample just shows whats visible in the taskbar. I ned to get all programs.
The other source seems very good, but unfortenetly im a litle bit to stupid to figure it out. The source code U posted was easy to use.
The other source seems very good, but unfortenetly im a litle bit to stupid to figure it out. The source code U posted was easy to use.
Listening
listening....., pointless, however if you want to see the biggest thread going, the biggest one i have ever seen is this... check it out :)
https://www.experts-exchange.com/jsp/qShow.jsp?ta=newcompusr&qid=10168979
see if anyone here can help?
https://www.experts-exchange.com/jsp/qShow.jsp?ta=newcompusr&qid=10168979
see if anyone here can help?
ok try this instead,whichever item is selected in listbox 2 will be the one that is hidden/shown or killed.
the listbox1 is hidden on formcreate and is there primarily to hold the handles of each item.
you could add third listbox(not hidden to add the path of exe to just uncomment the line i added for tat if you want it):
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,TlHelp32, ComCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
Button3: TButton;
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i : integer;
implementation
{$R *.DFM}
type
EnumWindowsProc = function (Hwnd: THandle;Param: Pointer): Bool; stdcall;
function GetWindowExeName(Handle: THandle): String;
var
PE: TProcessEntry32;
Snap: THandle;
ProcessId: cardinal;
begin
GetWindowThreadProcessId(H andle,@Pro cessId);
Snap:= CreateToolHelp32Snapshot(T H32CS_SNAP PROCESS, 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): Bool; stdcall;
var
Text,TempString: string;
begin
If (GetWindowLong(Hwnd,GWL_HW NDPARENT)= 0) then
begin
TempString := GetWindowExeName(Hwnd);
SetLength (Text, 100);
GetWindowText (Hwnd, PChar (Text), 100);
if text > ' ' then begin
Form1.Listbox1.Items.Add(I ntToStr(Hw nd));
Form1.Listbox2.Items.Add(t ext);
//Form1.listbox3.items.add (tempstrin g);//to add path also
end;
Result := True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
EWProc: EnumWindowsProc;
begin
Listbox1.Visible := false;
ListBox1.Items.Clear;
Listbox2.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
button1.caption := 'hide item';
button2.caption := 'show item';
button3.caption := 'kill item';
end;
procedure TForm1.ListBox2MouseDown(S ender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin //get a handle to selected item
i := ListBox1.ItemAtPos(Point(x ,y),True);
end;
procedure TForm1.Button1Click(Sender : TObject);
var
wnd :Hwnd;
begin
Wnd := hwnd(strToInt(listbox1.ite ms.Strings [i]));
Showwindow(Wnd,SW_HIDE);
end;
procedure TForm1.Button2Click(Sender : TObject);
var
wnd :Hwnd;
begin
Wnd := hwnd(strToInt(listbox1.ite ms.Strings [i]));
Showwindow(Wnd,SW_SHOW);
end;
procedure TForm1.Button3Click(Sender : TObject);
var
wnd :Hwnd;
temp :string;
EWProc: EnumWindowsProc;
ClickedOK : boolean;
begin
Wnd := hwnd(strToInt(listbox1.ite ms.Strings [i]));
PostMessage(Wnd,WM_SYSCOMM AND,SC_CLO SE, 0);
sleep(100);
ListBox1.Items.Clear;
Listbox2.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
end;
end.
the listbox1 is hidden on formcreate and is there primarily to hold the handles of each item.
you could add third listbox(not hidden to add the path of exe to just uncomment the line i added for tat if you want it):
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls,TlHelp32, ComCtrls;
type
TForm1 = class(TForm)
Button2: TButton;
Button3: TButton;
Button1: TButton;
ListBox1: TListBox;
ListBox2: TListBox;
procedure FormCreate(Sender: TObject);
procedure ListBox2MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i : integer;
implementation
{$R *.DFM}
type
EnumWindowsProc = function (Hwnd: THandle;Param: Pointer): Bool; stdcall;
function GetWindowExeName(Handle: THandle): String;
var
PE: TProcessEntry32;
Snap: THandle;
ProcessId: cardinal;
begin
GetWindowThreadProcessId(H
Snap:= CreateToolHelp32Snapshot(T
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): Bool; stdcall;
var
Text,TempString: string;
begin
If (GetWindowLong(Hwnd,GWL_HW
begin
TempString := GetWindowExeName(Hwnd);
SetLength (Text, 100);
GetWindowText (Hwnd, PChar (Text), 100);
if text > ' ' then begin
Form1.Listbox1.Items.Add(I
Form1.Listbox2.Items.Add(t
//Form1.listbox3.items.add
end;
Result := True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
EWProc: EnumWindowsProc;
begin
Listbox1.Visible := false;
ListBox1.Items.Clear;
Listbox2.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
button1.caption := 'hide item';
button2.caption := 'show item';
button3.caption := 'kill item';
end;
procedure TForm1.ListBox2MouseDown(S
Shift: TShiftState; X, Y: Integer);
begin //get a handle to selected item
i := ListBox1.ItemAtPos(Point(x
end;
procedure TForm1.Button1Click(Sender
var
wnd :Hwnd;
begin
Wnd := hwnd(strToInt(listbox1.ite
Showwindow(Wnd,SW_HIDE);
end;
procedure TForm1.Button2Click(Sender
var
wnd :Hwnd;
begin
Wnd := hwnd(strToInt(listbox1.ite
Showwindow(Wnd,SW_SHOW);
end;
procedure TForm1.Button3Click(Sender
var
wnd :Hwnd;
temp :string;
EWProc: EnumWindowsProc;
ClickedOK : boolean;
begin
Wnd := hwnd(strToInt(listbox1.ite
PostMessage(Wnd,WM_SYSCOMM
sleep(100);
ListBox1.Items.Clear;
Listbox2.Items.Clear;
EWProc := GetTitle;
EnumWindows (@EWProc, 0);
end;
end.
hello ..
Hi.... how are you
not too bad thanks ;-)
having some nice weather lately here ..
summer is coming :o)
having some nice weather lately here ..
summer is coming :o)
hehe, always has nice weather here, registered 32c about 90f in your terms here today.... :)
thanks for the "c" really appreciate it ,why do we bother ...
where i put
"just add 2 more buttons "
they are for show and hide so you would put the button1 code on all three buttons click event but on 2 of the buttons you would replace the line:
"PostMessage(Wnd,WM_SYSCOM
with
showwindow(wnd,sw_hide);
and
showwindow(wnd,sw_show);
cheers Barry