程序A.exe自己如何判断用户10分钟没有操作程序A.exe(一直在动Word),将程序A.exe关闭 程序A.exe自己如何判断用户10分钟没有操作程序A.exe(一直在动Word),将程序A.exe关闭请指教一下啦~呵呵~``谢谢各位! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 放个定时器,定为10分钟运行, 当A.exe的激活状态改变时,改变定时器 在onActivate事件中可以判断窗口是否在激活状态 这个可能不好办法!按楼上的方法,如果用户只在一个窗口中操作, 不关闭,不打开其他窗口,onActivate事件应该不能执行吧! “一直在动Word”是什么意思? 抄自同事xxx的代码------------------------------------------unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, AppEvnts;type TForm1 = class(TForm) ApplicationEvents1: TApplicationEvents; Timer1: TTimer; procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean); procedure Timer1Timer(Sender: TObject); private { Private declarations } LastActTime : TDateTime; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);begin 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) >= 10 then Begin LastActTime := now; //在这里处理 Close; end;end;end. sdzeng(大头鸟) 你的可以实现屏保类似。但是我想要的是,用户不使用我的程序超过10分钟,期间他还在用操作系统的,只是我的程序10分钟没 获得焦点~````怎么判断呢~~~~????? 还请指教哦~~ 窗体失去焦点和得到焦点会收到WM_KILLFOCUS ,WM_SETFOCUS消息可以重载这两个消息函数unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls,DateUtils;type TForm1 = class(TForm) Timer1: TTimer; procedure Timer1Timer(Sender: TObject); private { Private declarations } dtLastFocusTime : TDateTime; procedure onKillFocus(var Msg : TWMKillFocus);message WM_KILLFOCUS ; procedure OnSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS; public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.onKillFocus(var Msg: TWMKillFocus);begin dtLastFocusTime := Now; Timer1.Enabled := True;end;procedure TForm1.OnSetFocus(var Msg: TWMSetFocus);begin dtLastFocusTime := 0; Timer1.Enabled := False;end;procedure TForm1.Timer1Timer(Sender: TObject);begin if (dtLastFocusTime>0) and (SecondsBetween(Now,dtLastFocusTime)>=1) then begin dtLastFocusTime := Now; Timer1.Enabled := False; //在这里处理 end;end;end. 欢迎加入Borland DELPHI程序员,参与群里技术讨论!欢迎女孩子,也欢迎男孩子参与技术讨论!群号15154361 sdzeng(大头鸟) 大哥~``先谢谢你 你好象还是没明白我的意思我的应用程序有好多的窗口~~```我不能将代码只放在主窗口上的吧~```那样我操作子窗口的时候也会关闭的呀~```` 楼主是怎么定义“没有操作程序A.exe”?程序没有收到鼠标和键盘消息就可以认为是“没有操作程序”不知道楼主有没有试过6楼代码,执行其他程序,是不影响计时的 如果用程序是否活动的方式判断是否被使用的话,可以用下面的代码unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, AppEvnts, ExtCtrls,DateUtils;type TForm1 = class(TForm) ApplicationEvents1: TApplicationEvents; Timer1: TTimer; procedure Timer1Timer(Sender: TObject); procedure ApplicationEvents1Activate(Sender: TObject); procedure ApplicationEvents1Deactivate(Sender: TObject); private dtLastFocusTime : TDateTime; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);beginif (dtLastFocusTime>0) and (SecondsBetween(Now,dtLastFocusTime)>=1) then begin dtLastFocusTime := Now; Timer1.Enabled := False; Close; end;end;procedure TForm1.ApplicationEvents1Activate(Sender: TObject);begin dtLastFocusTime :=0; Timer1.Enabled := False;end;procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);begin dtLastFocusTime := Now; Timer1.Enabled := True;end;end. !!!(((求助))):谁去过吉林省辽源市出差? FASTREPORT的使用 StringGrid到底可不可以和Edit一样可以输入信息然后保存到数据库表里啊? delphi中能做主-子窗体的结构吗?如何实现?谢谢 DELPHI7 访问AccessXP数据库,总是报错,奇怪,什么都没干呢 不好意思,上一个问题问错了。各位请问,如何返'王'的Unicode 字符代码,及如何反过来求? Timage...如何改变大小? 初学者小问题(3) 急求 Delphi7第三方控件路径问题 Ado错误,我快疯了!!!!! c中单精度float类型(占四个字节)在delphi中如何转换? 寻找p2p合作伙伴。
onActivate事件应该不能执行吧!
------------------------------------------unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, AppEvnts;type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
Timer1: TTimer;
procedure ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
LastActTime : TDateTime;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
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) >= 10 then
Begin
LastActTime := now;
//在这里处理
Close;
end;
end;end.
你的可以实现屏保类似。
但是我想要的是,用户不使用我的程序超过10分钟,期间他还在用操作系统的,
只是我的程序10分钟没 获得焦点~````
怎么判断呢~~~~
?????
还请指教哦~~
可以重载这两个消息函数unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls,DateUtils;type
TForm1 = class(TForm)
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
dtLastFocusTime : TDateTime;
procedure onKillFocus(var Msg : TWMKillFocus);message WM_KILLFOCUS ;
procedure OnSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.onKillFocus(var Msg: TWMKillFocus);
begin
dtLastFocusTime := Now;
Timer1.Enabled := True;
end;procedure TForm1.OnSetFocus(var Msg: TWMSetFocus);
begin
dtLastFocusTime := 0;
Timer1.Enabled := False;
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (dtLastFocusTime>0) and (SecondsBetween(Now,dtLastFocusTime)>=1) then
begin
dtLastFocusTime := Now;
Timer1.Enabled := False;
//在这里处理
end;
end;end.
你好象还是没明白我的意思
我的应用程序有好多的窗口~~```
我不能将代码只放在主窗口上的吧~```
那样我操作子窗口的时候也会关闭的呀~````
程序没有收到鼠标和键盘消息就可以认为是“没有操作程序”
不知道楼主有没有试过6楼代码,执行其他程序,是不影响计时的
可以用下面的代码unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AppEvnts, ExtCtrls,DateUtils;type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure ApplicationEvents1Activate(Sender: TObject);
procedure ApplicationEvents1Deactivate(Sender: TObject);
private
dtLastFocusTime : TDateTime;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Timer1Timer(Sender: TObject);
begin
if (dtLastFocusTime>0) and (SecondsBetween(Now,dtLastFocusTime)>=1) then
begin
dtLastFocusTime := Now;
Timer1.Enabled := False;
Close;
end;end;procedure TForm1.ApplicationEvents1Activate(Sender: TObject);
begin
dtLastFocusTime :=0;
Timer1.Enabled := False;
end;procedure TForm1.ApplicationEvents1Deactivate(Sender: TObject);
begin
dtLastFocusTime := Now;
Timer1.Enabled := True;
end;end.