G
gxcddnk
Unregistered / Unconfirmed
GUEST, unregistred user!
我抄了一个程序,是3秒内鼠标键盘不动就触发一个操作,但是现在发现一个问题:如果那个操作是showmessage,就没问题;但是如果改成激活某个窗口到屏幕最前端就有问题:不管有没有鼠标键盘操作,在3秒内窗口都会被激活到屏幕最前端.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, AppEvnts,DateUtils;
type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
Timer1: TTimer;
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Oclock:TTimer;
IdleTimeLimited:Integer;
LastActTime:TDateTime;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
//如果已经定义主系统的Application的OnMessage事件则先调用;
//处理键盘、鼠标消息
if ((Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST)) or
((Msg.message >= WM_MOUSEFIRST) and (Msg.message <= WM_MOUSELAST))then
LastActTime := now;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//如果键盘、鼠标在指定的时间内没有消息,调用处理事件
if SecondsBetween(now,LastActTime) > IdleTimeLimited then Begin
LastActTime := now;
ShowMessage('本程序未活动时间超过'+IntToStr(IdleTimeLimited)+'秒!');
// application.BringToFront;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LastActTime := now;
IdleTimeLimited := 3;
Oclock := TTimer.Create(self);
Oclock.Enabled := True;
//设置时间控件的时间事件
Oclock.OnTimer := Timer1Timer;
Application.OnMessage := ApplicationEvents1Message;
end;
end.
以上ShowMessage('本程序未活动时间超过'+IntToStr(IdleTimeLimited)+'秒!');
改成application.BringToFront就会有我上面说的问题.
请解答一下.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, AppEvnts,DateUtils;
type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
Timer1: TTimer;
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Oclock:TTimer;
IdleTimeLimited:Integer;
LastActTime:TDateTime;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
//如果已经定义主系统的Application的OnMessage事件则先调用;
//处理键盘、鼠标消息
if ((Msg.message >= WM_KEYFIRST) and (Msg.message <= WM_KEYLAST)) or
((Msg.message >= WM_MOUSEFIRST) and (Msg.message <= WM_MOUSELAST))then
LastActTime := now;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
//如果键盘、鼠标在指定的时间内没有消息,调用处理事件
if SecondsBetween(now,LastActTime) > IdleTimeLimited then Begin
LastActTime := now;
ShowMessage('本程序未活动时间超过'+IntToStr(IdleTimeLimited)+'秒!');
// application.BringToFront;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
LastActTime := now;
IdleTimeLimited := 3;
Oclock := TTimer.Create(self);
Oclock.Enabled := True;
//设置时间控件的时间事件
Oclock.OnTimer := Timer1Timer;
Application.OnMessage := ApplicationEvents1Message;
end;
end.
以上ShowMessage('本程序未活动时间超过'+IntToStr(IdleTimeLimited)+'秒!');
改成application.BringToFront就会有我上面说的问题.
请解答一下.