程序A.exe自己如何判断用户10分钟没有操作程序A.exe(一直在动Word),将程序A.exe关闭
请指教一下啦~呵呵~``谢谢各位!

解决方案 »

  1.   

    放个定时器,定为10分钟运行, 当A.exe的激活状态改变时,改变定时器
      

  2.   

    在onActivate事件中可以判断窗口是否在激活状态
      

  3.   

    这个可能不好办法!按楼上的方法,如果用户只在一个窗口中操作, 不关闭,不打开其他窗口,
    onActivate事件应该不能执行吧!
      

  4.   

    “一直在动Word”是什么意思?
      

  5.   

    抄自同事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.
      

  6.   

    sdzeng(大头鸟) 
    你的可以实现屏保类似。
    但是我想要的是,用户不使用我的程序超过10分钟,期间他还在用操作系统的,
    只是我的程序10分钟没 获得焦点~````
    怎么判断呢~~~~
    ????? 
    还请指教哦~~
      

  7.   

    窗体失去焦点和得到焦点会收到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.
      

  8.   

    欢迎加入Borland DELPHI程序员,参与群里技术讨论!欢迎女孩子,也欢迎男孩子参与技术讨论!群号15154361
      

  9.   

    sdzeng(大头鸟) 大哥~``先谢谢你 
    你好象还是没明白我的意思
    我的应用程序有好多的窗口~~```
    我不能将代码只放在主窗口上的吧~```
    那样我操作子窗口的时候也会关闭的呀~````
      

  10.   

    楼主是怎么定义“没有操作程序A.exe”?
    程序没有收到鼠标和键盘消息就可以认为是“没有操作程序”
    不知道楼主有没有试过6楼代码,执行其他程序,是不影响计时的
      

  11.   

    如果用程序是否活动的方式判断是否被使用的话,
    可以用下面的代码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.