I am running some shell command using which i execute some forms or some application, at this point i wanted to read the caption of the running form's caption.
Printable View
I am running some shell command using which i execute some forms or some application, at this point i wanted to read the caption of the running form's caption.
Shell the program and add this code, assuming that the application launced will be the one with focus.
VB Code:
Private Declare Function GetForegroundWindow _ Lib "user32" () As Long Private Declare Function GetWindowTextLength _ Lib "user32" Alias "GetWindowTextLengthA" (ByVal _ hwnd As Long) 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 Declare Function GetParent Lib "user32" (ByVal _ hwnd As Long) As Long Private 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 Private 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
Matthew: How, and from where, would you execute your code to the get caption of an open window?