Public Class Form1
Private CurrentApp_hWnd
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetForegroundWindow Lib "user32.dll" () As Long
Function GetCaption(ByVal hwnd As Long)
Dim hWndTitle As String
hWndTitle = String(GetWindowTextLength(hwnd), 0)
GetWindowText(hwnd, hWndTitle, (GetWindowTextLength(hwnd) + 1))
GetCaption = hWndTitle
End Function
Private Sub Form_Load()
If GetForegroundWindow <> CurrentApp_hWnd Then
CurrentApp_hWnd = GetForegroundWindow
If GetCaption(GetForegroundWindow) = "" Then Else : TextBox1.Text = TextBox1.Text & " [" & GetCaption(GetForegroundWindow) & "] - "
End If
End Sub
End Class