2013-10-15
展开全部
思路,用windows API函数 GetForegroundWindow 得到前台窗口的句柄,然后跟窗口的句柄比较...
如果相同就是得到焦点,否则失去焦点,例子中我用的timer检测,,,,,,代码如下
Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Dim thwnd As Long
thwnd = GetForegroundWindow
If thwnd <> Me.hWnd Then
Me.Caption = "失去焦点"
Else
Me.Caption = "得到焦点"
End If
End Sub
如果相同就是得到焦点,否则失去焦点,例子中我用的timer检测,,,,,,代码如下
Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub Form_Load()
Timer1.Interval = 10
End Sub
Private Sub Timer1_Timer()
Dim thwnd As Long
thwnd = GetForegroundWindow
If thwnd <> Me.hWnd Then
Me.Caption = "失去焦点"
Else
Me.Caption = "得到焦点"
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询