Für dieses Beispiel brauchen Sie ein Formular und eine Textbox sowie einen Timer.
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetClassName _
Lib "user32" Alias "GetClassNameA" _
(ByVal hwnd As Long, ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetCursorPos _
Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint _
Lib "user32" (ByVal xPoint As Long, _
ByVal yPoint As Long) As Long
Private Function FindeFenster()
Dim pApi As POINTAPI
Dim hWn As Long
Dim KlassenName As String * 255
GetCursorPos pApi
hWn = WindowFromPoint(pApi.X, pApi.Y)
GetClassName hWn, KlassenName, 255
FindeFenster = KlassenName
End Function
Private Sub Form_Load()
' Timerintervall einstellen
Timer1.Interval = 100
End Sub
Private Sub Timer1_Timer()
Text1.Text = FindeFenster()
End Sub