Public Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
Dim i As Long
Dim j As Long
i = GetForegroundWindow
If ReturnParent Then
Do While i <> 0
j = i
i = GetParent(i)
Loop
i = j
End If
GetActiveWindowTitle = GetWindowTitle(i)
End Function
Public Function GetWindowTitle(ByVal hwnd As Long) As String
Dim l As Long
Dim s As String
l = GetWindowTextLength(hwnd)
s = Space(l + 1)
GetWindowText hwnd, s, l + 1
GetWindowTitle = Left$(s, l)
End Function