The GetForegroundWindow function returns a handle to the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads.<br>通过判断当前最顶层窗体的handle,你可有用两个变量保存进行比较.<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br> hwd: THandle;<br> buf: PChar;<br>begin<br>// hwd := GetActiveWindow;<br> GetMem(buf,1024);<br> hwd := GetForegroundWindow;<br> if hwd <>0 then<br> begin<br> GetWindowText(hwd,buf,1024);<br> Memo1.Lines.Add(Format('Caption:%s,Handle:%d',[buf,hwd]));<br> end;<br>end;