请创建一个工程,加上一个Buuton和一个ListBox1控件,试试下面这段程序:
procedure TForm1.Button1Click(Sender: TObject);
var
hCurrentWindow: HWnd;
szText: array[0..254] of char;
begin
hCurrentWindow := GetWindow(Handle, GW_HWNDFIRST);
While hCurrentWindow <> 0 Do
Begin
If GetWindowText(hCurrentWindow, @szText, 255) > 0 Then
ListBox1.Items.add(Strpas(@szText));
hCurrentWindow := GetWindow(hCurrentWindow, GW_HWNDNEXT);
End;
end;