[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

How do I get a list of the applications in the taskbar?

I wrote a little piece of code in Delphi that retrieves me the list of all the windows running at a time (using EnumWindows).
The problem I have is that seems to list about every little window running, even those inside the applications.
I think I should go other route, since this EnumWindows gets windows, not applications running.

What should I use else?
0
fischermx
Asked:
fischermx
  • 4
  • 2
1 Solution
 
ThievingSixCommented:
Do you want to get all the processes like the task manager processes tab? If so: http://www.swissdelphicenter.ch/torry/showcode.php?id=616
0
 
fischermxAuthor Commented:
Nope, I want the applications in the task bar.
0
 
KillerCodeCommented:
How-To
 Memo1.Text := ListWindows(1); //Include Inivisble
 Memo1.Text := ListWindows(0); //Don't Include Inivisble

PS : WindowList MUST be a global Variable (Before "Implementation")
var
 WindowList:String;
 
function GetWindowState(Handle: HWND):String;
begin
  If IsWindowVisible(Handle) Then Result := 'Visible'
  Else Result := 'Invisible';
end;
 
function ListWindows(INV:Integer):String;
 
  function EnumWindowProc(Hwnd: HWND; i: integer): boolean; stdcall;
  var
   Titulo : string;
  begin
   if Hwnd <> 0 then
   begin
    SetLength(Titulo, 255);
    SetLength(Titulo, GetWindowText(Hwnd, PChar(Titulo), Length(Titulo)));
    if i = 1 Then if (Titulo<>'') then WindowList := WindowList + GetWindowState(Hwnd) + #9 + Titulo + #9 + IntToStr(Hwnd) + #13#10;
    if I = 0 Then if (IsWindowVisible(Hwnd)) and (Titulo <> '') then WindowList := WindowList + #9 + Titulo + #9 + IntToStr(Hwnd) + #13#10;
   end;
  Result := true;
  end;
begin
 WindowList := '';
 EnumWindows(@EnumWindowProc, Inv);
 Result := WindowList;
end;

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fischermxAuthor Commented:

Great!, The "IsWindowVisible" is what I was looking for.
That did it!! Thank you very much.

Can I ask something more...... how do I get which is the Active window?
I see that in the list of applications filled by EnumWindows the first one seems to be the active one, but I'm not sure if this if I can take this as granted.
0
 
KillerCodeCommented:
Easy too, just use GetForegroundWindow and then Get the Text from this handle
function ActiveWindow:string;
var
 Handle: THandle;
 Len: LongInt;
 Title: string;
begin
 Handle := GetForegroundWindow;
 Len := GetWindowTextLength(Handle) + 1;
 SetLength(Title, Len);
 GetWindowText(Handle, PChar(Title), Len);
 ActiveWindow := Trim(Title);
end;

Open in new window

0
 
fischermxAuthor Commented:
Thank you!!
0
 
fischermxAuthor Commented:
Thank you!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now