Option Explicit
Private Declare Function GetFocus Lib "user32" () As Long
Dim a As LongPrivate Sub Timer1_Timer()
'得到焦点的窗口句柄
a = GetFocus
If Text1.hWnd = a Then
MsgBox "焦点在TextBox1上"
ElseIf Text2.hWnd = a Then
MsgBox "焦点在TextBox2上"
ElseIf Text3.hWnd = a Then
MsgBox "焦点在TextBox3上"
End If
End Sub
Private Declare Function GetFocus Lib "user32" () As Long
Dim a As LongPrivate Sub Timer1_Timer()
'得到焦点的窗口句柄
a = GetFocus
If Text1.hWnd = a Then
MsgBox "焦点在TextBox1上"
ElseIf Text2.hWnd = a Then
MsgBox "焦点在TextBox2上"
ElseIf Text3.hWnd = a Then
MsgBox "焦点在TextBox3上"
End If
End Sub
case "Text1"
MsgBox "焦点在TextBox1上"
case "Text2"
MsgBox "焦点在TextBox2上"case "Text3"
MsgBox "焦点在TextBox3上"end select