enumwindows是一个callback函数
先声明一个callback function (不要放在类声明区)
function EnumWindowsProc(AHWnd: HWnd;
LPARAM: lParam): boolean;
stdcall;
var
WndCaption: array[0..254] of char;
WndClassName: array[0..254] of char;
begin
if pos('Microsoft Internet',wndcaption)<>0 then
//指定窗口的title
begin
GetWindowText(AHWnd, @WndCaption, 254);
GetClassName(AHWnd, @WndClassName, 254);
with Form1.Memo1.Linesdo
begin
Add(StrPas(WndCaption));
Add(StrPas(WndClassName));
add(inttostr(ahwnd));
Add('-------');
end;
Result := True;
end;
调用:
procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Lines.Clear;
EnumWindows(@EnumWindowsProc, 0);
//传指针
end;