Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Form_Load()
Timer1.Interval = 100 ' 设置定时器间隔(单位:毫秒)
Timer1.Enabled = True ' 启动定时器
End Sub
Private Sub Timer1_Timer()
If GetForegroundWindow() = 0 Then
MsgBox "已锁屏"
End If
End Sub