Results 1 to 3 of 3

Thread: How to find the Caption

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2001
    Location
    India
    Posts
    20

    Angry How to find the Caption

    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.

  2. #2
    Matthew Gates
    Guest
    Shell the program and add this code, assuming that the application launced will be the one with focus.


    VB Code:
    1. Private Declare Function GetForegroundWindow _
    2. Lib "user32" () As Long
    3.  
    4. Private Declare Function GetWindowTextLength _
    5. Lib "user32" Alias "GetWindowTextLengthA" (ByVal _
    6. hwnd As Long) As Long
    7.  
    8. Private Declare Function GetWindowText Lib "user32" _
    9. Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
    10. lpString As String, ByVal cch As Long) As Long
    11.  
    12. Private Declare Function GetParent Lib "user32" (ByVal _
    13. hwnd As Long) As Long
    14.  
    15.  
    16. Private Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
    17.    Dim i As Long
    18.    Dim j As Long
    19.  
    20.    i = GetForegroundWindow
    21.  
    22.  
    23.    If ReturnParent Then
    24.       Do While i <> 0
    25.          j = i
    26.          i = GetParent(i)
    27.       Loop
    28.  
    29.       i = j
    30.    End If
    31.  
    32.    GetActiveWindowTitle = GetWindowTitle(i)
    33. End Function
    34.  
    35.  
    36. Private Function GetWindowTitle(ByVal hwnd As Long) As String
    37.    Dim l As Long
    38.    Dim s As String
    39.  
    40.    l = GetWindowTextLength(hwnd)
    41.    s = Space$(l + 1)
    42.  
    43.    GetWindowText hwnd, s, l + 1
    44.  
    45.    GetWindowTitle = Left$(s, l)
    46. End Function

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Matthew: How, and from where, would you execute your code to the get caption of an open window?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width