如果想要被动的获得这些窗体的激活消息,我想一般是不可能的,除非自己截获。 不过如果要求不是很高的话,可以使用下面的方法试一试: procedure TForm1.Timer1Timer(Sender: TObject); var wnd: THandle; buf: PChar; begin wnd:= GetForegroundWindow(); if wnd=NULL then begin memo1.Lines.Add('Return Handle NULL!'); exit; end; if memo1.Lines.Count>500 then memo1.Clear; getmem(buf, 256); GetWindowText(wnd, buf, 255); memo1.Lines.Add(String(buf)); end;
不过如果要求不是很高的话,可以使用下面的方法试一试:
procedure TForm1.Timer1Timer(Sender: TObject);
var wnd: THandle;
buf: PChar;
begin
wnd:= GetForegroundWindow();
if wnd=NULL then begin
memo1.Lines.Add('Return Handle NULL!'); exit;
end; if memo1.Lines.Count>500 then memo1.Clear;
getmem(buf, 256);
GetWindowText(wnd, buf, 255);
memo1.Lines.Add(String(buf));
end;
b表单是否获得焦点,是可以的,我这样做过一个程序,不过我认为实际不太好。