?
Solved

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

Posted on 2009-05-15
7
Medium Priority
?
297 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared 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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

743 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