你自己试试看吧。
{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 windowdo
es 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;
procedure TForm1.Button1Click(Sender: TObject);
var
FoundWindow: HWND;
WindowText: array[0..255] of char;
begin
{find a TEdit child window}
FoundWindow:=FindWindowEx(Form1.Handle, 0, 'TEdit',nil);
{get its text...}
GetWindowText(FoundWindow, WindowText, 255);
{...and display it}
Label1.Caption:='FindWindowEx found window handle '+IntToStr(FoundWindow)+
': '+WindowText;
end;