Sie brauchen für diesen Tipp eine Userform, einen Label (Label1) und einen Timer (Timer1). Sobald ein Fenster den Fokus bekommt (aktiv wird), ändert sich die Anzeige im Label.
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias _
"GetWindowTextA" (ByVal hwnd As Long, _
ByVal lpString As String, ByVal cch As Long) As Long
Private Sub Form_Load()
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Static lHwnd As Long
Dim lCurHwnd As Long
Dim sText As String * 255
lCurHwnd = GetForegroundWindow
If lCurHwnd = lHwnd Then Exit Sub
lHwnd = lCurHwnd
If lHwnd <> hwnd Then
Label1.Caption = "Aktives Fenster: " & Left$(sText, _
GetWindowText(lHwnd, ByVal sText, 255))
Else
Label1.Caption = "Aktives Fenster: Form1"
End If
End Sub