高分求救(300)(300分)

  • 主题发起人 主题发起人 DelphiTony
  • 开始时间 开始时间
D

DelphiTony

Unregistered / Unconfirmed
GUEST, unregistred user!
[:(!]怎么样判断一个应用程序响应键盘或鼠标的活动?<br>比如:我要控制程序在30分钟的时候如果键盘或鼠标没有对它操着的话,就退出当前的程序。<br>各位大侠帮帮忙吧,我要的很急,答对一定给分300。
 
我都想了解<br><br>幫你頂一下
 
加上TApplicationEvents控件,在onmessage事件中每发生一次鼠标事件就复位定时器.
 
先定义一个全局变量来记录上一次操作的时间Ld_LastDate:TDateTime<br>procedure AppMessage(var Msg: TMsg; var Handled: Boolean);<br>begin<br>&nbsp;if (msg.message=WM_MOUSEACTIVATE) or (....) then<br>&nbsp; &nbsp;Ld_LastDate:=Now;<br>end;<br>Application.onmessage:=AppMessage;<br>然后定一个计时器30分钟一次<br>procedure Timer1.ontimer(sender:tobject);<br>begin<br>&nbsp;if ld_lastdate=0 then<br>&nbsp; application.Terminate<br>&nbsp;else<br>&nbsp; ld_lastdate:=0;<br>end;
 
TApplicationEvents和Ttimer结合使用即可<br>procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; var Handled: Boolean);<br>begin<br>&nbsp;// if (Msg.Message=wm_lMouseDown)....then &nbsp;//可再对消息具体进行判断和过滤处理<br>&nbsp; Timer1.Enabled := False;<br>end;<br><br>procedure TForm1.ApplicationEvents1Idle(Sender: TObject;<br>&nbsp; var Done: Boolean);<br>begin<br>&nbsp; Timer1.Enabled := True;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin <br>&nbsp; showmessage('30分钟未动')<br>end;<br>TApplicationEvents在additional组件中<br>Ttimer设interval为30*60*1000<br><br><br>
 
<br><br>if (msg.message=WM_KEYDOWN)or(msg.Message=WM_MOUSEMOVE) then<br>&nbsp; &nbsp; &nbsp; c:=0;//c為全局<br>這樣只能對該程序操作時有效(好像程序不要激活狀態下就無效)<br><br><br>順便問一下﹕<br>各位有沒有在不激活狀態下也同樣有效的方法?
 
是呀,stuwe 大侠的问题值得关注呀.
 
哇!300分耶!<br><br>看招:<br>1.把ttime放入form,把Additional中的ApplicationEvents也放入Form,设置<br>它的onmessage事件。<br><br>2.见下面的代码:<br><br>var<br>&nbsp; _time:word=0;//分钟时间计数<br><br>procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;<br>&nbsp; var Handled: Boolean);<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (Msg.message=WM_MOUSEMOVE) &nbsp; or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Msg.message=WM_LBUTTONDOWN) or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Msg.message=WM_RBUTTONDOWN) or<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(Msg.message=WM_KEYDOWN) &nbsp; &nbsp; Then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_time:=0; //本程序有鼠标或键盘动作,重新开始计数<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Timer1.Interval:=60*1000; { 1分钟 }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inc(_time);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (_time&gt;=30) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Timer1.Enabled:=false;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; close;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>end;<br><br>3.搞定!给分!<br>
 
大哥,这个是在delphi2.0下用的。不好意思,我忘了高诉你了。<br>在delphi2.0中没有ApplicationEvents呀。<br>如果是在delphi6.0中是可以的。<br>但我现在不是呀,所以还不能送分,请再帮想想!<br>谢谢!
 
没有ApplicationEvents,但有Application吧(实在不记得了),<br>让Application.OnMessage:=...<br>不就行了.
 
ApplicationEvents
 
别搞得那么复杂,看下面的:<br>可以如下方法解决:<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; ExtCtrls;<br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; &nbsp; procedure WndProc(var Msg: TMessage); override;<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; TimeCount:integer;<br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.WndProc(var Msg: TMessage);<br>begin<br>&nbsp; inherited;<br>&nbsp; timeCount:=0;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>&nbsp; inc(timeCount);<br>&nbsp; if timecount=1800 then close;<br>end;<br><br>end.<br>
 
楼上大哥能不能解释一下呀?
 
难道你要发分了?<br>呵呵<br>你看一下wndproc的帮助吧,这里重写了一下而与.
 
procedure TForm1.WndProc(var Msg: TMessage);<br>begin<br>&nbsp; inherited;<br>&nbsp; &nbsp; if (Msg.MSG=WM_MOUSEMOVE) &nbsp; or<br>&nbsp; &nbsp; &nbsp; &nbsp;(Msg.MSG=WM_LBUTTONDOWN) or<br>&nbsp; &nbsp; &nbsp; &nbsp;(Msg.MSG=WM_RBUTTONDOWN) or<br>&nbsp; &nbsp; &nbsp; &nbsp;(Msg.MSG=WM_KEYDOWN) &nbsp; &nbsp; Then<br>&nbsp; &nbsp; &nbsp; &nbsp;timeCount:=0; //本程序有鼠标或键盘动作,重新开始计数<br>end;<br>
 
来晚了,Highpeak的方法加上wql的方法才是最好的.
 
有沒有類似于屏保那樣<br><br>不管程序是不是激活都有效
 
楼上的Highpeak哥,你这种做法不是我要求的,当鼠标离开时就触发,停在窗体上面时 就不触发了。
 

Similar threads

后退
顶部