Solved

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

Posted on 2009-05-15
7
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi problems to abort a printjob 9 44
Microsoft Access 97 and Delphi XE2 9 82
firemonkey Android Listview Sort items 7 95
Developing a front end to SPLUNK 1 99
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…

740 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