Enumerate Windows

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.

 

Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

Here is a program that uses the Windows API function EnumWindows to find and return all top-level windows  or running programs.    Calls to EnumWindows take two parameters, a pointer to a callback procedure which is passed the handle of each top-level window and an arbitrary parameter which I use to pass the address of a Tstringlist to hold the results.    

I made three versions of the callback procedure called from three different buttons - NextWindow builds a list window titles, NextProgram builds a list running programs, and NextBoth builds a list with both.       Callback procedures must be specified with stdcall  so that parameters passed by EnumWindows are interpreted correctly.   

The code to retrieve the program associated with a window handle is contained in function GetWindowExeName which returns a string representing the executable name.   The details of this function are a mystery to me - I lifted it from the Delphi section of experts-exchange.com  with a minor correction or two.   I filter out duplicate occurrences so that only each program only appears once in the resulting list.    

A final button tests the main motivation for  this program; an  IsRunning function which takes a program name as a parameter and returns true or false depending on whether that program is currently running. 

Download source 

Download Executable

 

Created: February 4, 2003

Modified: February 18, 2016

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2016, Gary Darby    All rights reserved.