原理:利用两个时间点的光标座标值是否相同来判断当前程序是否有无操作。如果当前活动程序不是ACCESS,则计时退出功能无效,如果是,则启用,新旧座标值一样时,超过计时器长短时间即会自动退出。 将以下代码COPY到模块中:
Option Compare Database Public Type POINTAPI
X As Long
Y As Long
End Type Public OldPoint As POINTAPI, NewPoint As POINTAPI
Public XX As Integer
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetActiveWindow Lib "user32" () As Long
建一窗体,将以下代码COPY到窗体的模块中:
Option Compare Database Private Sub Form_Load()
GetCursorPos OldPoint
End Sub Private Sub Form_Timer()
Dim I
I = GetActiveWindow '获取活动窗口的句柄,如当前系统没有窗口处于活动状态,则返回零值
If I <> 0 Then '当前程序为本系统时,根据光标是否有移动来判断
GetCursorPos NewPoint '获取新的光标位置
If OldPoint.X = NewPoint.X And OldPoint.Y = NewPoint.Y Then
DoCmd.Quit acQuitSaveAll '判断为是,则光标停留在原处未动过,退出系统
Else
OldPoint.X = NewPoint.X '判断为否,以新的坐标值代替旧的坐标值。
OldPoint.Y = NewPoint.Y
End If
XX = 0 '清除当前不为本系统时的计数器
Else
XX = XX + 1
If XX >= 2 Then DoCmd.Quit acQuitSaveAll
End If End Sub |