试试下面的,TApplicationEvents+Ttimer<br>假设超过10秒没动作需要重复登录<br>//呵呵,抱歉,刚才发贴的时候,多写了个判断,错了<br>//用下面这个修改过的吧,可以解决最小化的问题(或者说,这样无所谓是不是最小化)<br><br><br>unit Unit1;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, ExtCtrls, AppEvnts;<br><br>type<br> TForm1 = class(TForm)<br> ApplicationEvents1: TApplicationEvents;<br> Timer1: TTimer;<br> Button1: TButton;<br> procedure FormCreate(Sender: TObject);<br> procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);<br> procedure Timer1Timer(Sender: TObject);<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> FLogined:boolean; {是否已登录}<br> procedure SetLogin(value:boolean);<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.SetLogin(value:boolean);<br>begin<br> FLogined:=not value;<br> if not FLogined then<br> begin<br> timer1.Enabled:=false;<br> self.Caption:='要登录';<br> //showmessage('要登录');<br> FLogined:=true;<br> end<br> else<br> self.Caption:='已登录';<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br> timer1.Interval:=10000;<br> timer1.Enabled:=false;<br> SetLogin(true);<br>end;<br><br>procedure TForm1.ApplicationEvents1Idle(Sender: TObject;<br> var Done: Boolean);<br>begin<br> if FLogined then<br> begin<br> if not application.Active then<br> SetLogin(true)<br> else<br> timer1.Enabled:=true;<br> end;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> SetLogin(true);<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br> SetLogin(false);<br>end;<br><br>end.