在vb窗体无鼠标事件时,在软件界面有类似屏保的功能

来源:百度知道 编辑:UC知道 时间:2024/06/23 15:29:26
我想达到一个效果就是
在软件长时间没有鼠标活动,比如点击,那么界面除了标题栏外,用其他的视觉效果来代替,比如一幅图片或者一个flash

不知道怎么去判断是否有鼠标活动事件

'用 API 函数配合控件 Timer1,不管活动窗口是那一个,都能检测键盘和鼠标状态
'运行后,请留意本窗口标题栏给出的信息
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetCursorPos& Lib "user32" (lpPoint As PointAPI)
Private Type PointAPI
X As Long: Y As Long
End Type
Dim ctTimer As Single

Private Sub Form_Load()
Timer1.Enabled = True: Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim T As Single
T = Format(Timer - ctTimer, "0.0")
If KeyOrMouse() Then T = 0: ctTimer = Timer
Me.Caption = "鼠标和键盘未动时间:" & T & " 秒"
End Sub
Private Function KeyOrMouse() As Boolean
Static x0 As Long, y0 As Long
Dim nMouse As PointAPI, I As Long, dl As Long

'检测鼠标 是否移动
Call GetCursorPos(nMouse) '获取当前鼠标位置
If x0 <> nMouse.X Or y0 <> nMouse.Y Then KeyOr