Link to home
Start Free TrialLog in
Avatar of SwOoPe
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
Avatar of inthe
inthe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of inthe
inthe

opps missed some stuff .
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_SYSCOMMAND,SC_CLOSE, 0); "
with
showwindow(wnd,sw_hide);
and
showwindow(wnd,sw_show);

cheers Barry
Avatar of SwOoPe

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.
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?
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(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): Bool; stdcall;
 var
  Text,TempString: string;
begin
  If (GetWindowLong(Hwnd,GWL_HWNDPARENT)=0) then
  begin
TempString := GetWindowExeName(Hwnd);
  SetLength (Text, 100);
  GetWindowText (Hwnd, PChar (Text), 100);
  if text > ' ' then  begin
  Form1.Listbox1.Items.Add(IntToStr(Hwnd));
  Form1.Listbox2.Items.Add(text);
//Form1.listbox3.items.add(tempstring);//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(Sender: 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.items.Strings[i]));
Showwindow(Wnd,SW_HIDE);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
wnd :Hwnd;
begin
Wnd := hwnd(strToInt(listbox1.items.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.items.Strings[i]));
PostMessage(Wnd,WM_SYSCOMMAND,SC_CLOSE, 0);
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)
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 ...