Solved

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

Posted on 2009-05-15
7
293 Views
Last Modified: 2013-12-03
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
Comment
Question by:fischermx
  • 4
  • 2
7 Comments
 
LVL 13

Expert Comment

by:ThievingSix
ID: 24401369
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
 
LVL 1

Author Comment

by:fischermx
ID: 24401391
Nope, I want the applications in the task bar.
0
 
LVL 1

Accepted Solution

by:
KillerCode earned 500 total points
ID: 24401396
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
Independent Software Vendors: 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!

 
LVL 1

Author Comment

by:fischermx
ID: 24403445

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
 
LVL 1

Expert Comment

by:KillerCode
ID: 24403465
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
 
LVL 1

Author Comment

by:fischermx
ID: 24403690
Thank you!!
0
 
LVL 1

Author Closing Comment

by:fischermx
ID: 31582162
Thank you!!
0

Featured Post

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi Yen format 3 57
Need a complete list of ASP.NET page load events 3 63
SSRS Deployment problem 5 90
Delphi TListView and TEdit (Select item and input into TEdit) 10 40
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question