unit winHWND;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
ListBox1: TListBox;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
function EnumWndProc(AWnd: HWND; AlParam: LPARAM): Bool; stdcall;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWndProc,1);
end;
function TForm1.EnumWndProc(AWnd: HWND; AlParam: LPARAM): Bool;stdcall;
var
szText: array[0..254] of char;
begin
Result := True;
if IsWindowVisible(awnd) and (awnd<>Form1.Handle) then //要排除掉本窗口
begin
GetWindowText(awnd, @szText, 255);
if szText<>'' then
begin
listBox1.Items.Add(inttostr(awnd)+': '+strPas(@szText));
Result:=False;
end;
end;
end;
end.