关于此函数:
Unit
Windows.Pas
Syntax
EnumWindows(
lpEnumFunc: TFNWndEnumProc; {the address of the enumeration callback function}
lParam: LPARAM {a 32 bit application defined value}
): BOOL; {returns TRUE or FALSE}
Description
This function parses through all top-level windows on the screen, passing the handle of each window to an application defined callback function. This continues until all top-level windows have been enumerated or the callback function returns FALSE. The EnumWindows function does not enumerate child windows.
Parameters
lpEnumFunc: The address of the application defined callback function.
lParam: A 32 bit application defined value that will be passed to the callback function.
Return Value
If this function succeeds, it returns TRUE; otherwise it returns FALSE.
Callback Syntax
EnumWindowsProc(
hWnd: HWND; {a handle to a top-level window}
lParam: LPARAM {the application defined data}
): BOOL; {returns TRUE or FALSE}
Description
This function receives the window handle for each top-level window in the system, and may perform any desired task.
Parameters
hWnd: The handle of a top-level window being enumerated.
lParam: A 32 bit application defined value. This value is intended for application specific use inside of the callback function, and is the value of the lParam parameter passed to the EnumWindows function.
Return Value
The callback function should return TRUE to continue enumeration; otherwise it should return FALSE.
The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl
下面是个Example
{our callback function prototype}
function EnumerateWindows(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;
var
Form1: TForm1;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
{empty the listbox that will hold the window names}
ListBox1.Items.Clear;
{enumerate all the top-level windows in the system}
EnumWindows(@EnumerateWindows,0);
end;
{these steps execute for every top-level window in the system}
function EnumerateWindows(hWnd: HWND; lParam: LPARAM): BOOL;
var
TheText: Array[0..255] of char; // this holds the window text
begin
{if the window does not have any text...}
if (GetWindowText(hWnd, TheText, 255)=0) then
{...display the window handle and a note...}
Form1.ListBox1.Items.Add(Format('%d = {This window has no text}',[hWnd]))
else
{otherwise display the window handle and the window text}
Form1.ListBox1.Items.Add(Format('%d = %s',[hWnd,TheText]));
{continue enumeration}
Result:=TRUE;
end;