Results 1 to 4 of 4

Thread: Getting Windows text via the API

  1. #1
    zML
    Guest

    Getting Windows text via the API

    I have been trying to figure out how to get the full name of a window to show up in a msgbox for quite some time. I am not sure how to grab the name of a window via user32 and have it popup in a msgbox in my program.

    I have been trying to use showwindow and getwindowtext in order to do this. I am having problems poiting to a window OUTSIDE of my VB program. I can return the name of "form1" just fine, but I want the window name of a program totally outside my VB program.

    Any suggestions would be greatly appreciated.

    Thanks,

    Zac

  2. #2
    zML
    Guest
    I tried the following code, but the problem is Clarify is only the first 7 characters of the title of the window. The full title of the window is "Clarify - ClearSupport - [Clarify U.S.] - SRX011204605600." I'm wondering if there is a way to check only the first 7 characters of a window ? I only need to find the first instance of the window and return the last 15 characters of the Window's title..... Any suggestions ?


    Private Sub Command1_Click()
    Dim hWnd As Long ' receives handle to the found window
    Dim retval As Long ' generic return value

    hWnd = FindWindow(vbNullString, "Clarify")
    If hWnd = 0 Then
    MsgBox "Clarify isn't running"
    Else
    retval = FlashWindow(hWnd, 1)
    retval = FlashWindow(hWnd, 0)
    End If

    End Sub

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try this:
    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.  
    17. Private Function GetActiveWindowTitle(ByVal ReturnParent As Boolean) As String
    18. Dim i As Long
    19. Dim j As Long
    20.  
    21. i = GetForegroundWindow
    22.  
    23.  
    24. If ReturnParent Then
    25. Do While i <> 0
    26. j = i
    27. i = GetParent(i)
    28. Loop
    29.  
    30. i = j
    31. End If
    32.  
    33. GetActiveWindowTitle = GetWindowTitle(i)
    34. End Function
    35.  
    36.  
    37. Private Function GetWindowTitle(ByVal hwnd As Long) As String
    38. Dim l As Long
    39. Dim s As String
    40.  
    41. l = GetWindowTextLength(hwnd)
    42. s = Space$(l + 1)
    43.  
    44. GetWindowText hwnd, s, l + 1
    45.  
    46. GetWindowTitle = Left$(s, l)
    47. End Function
    48. 'Posted by Matthew Gates 10/30/2001

  4. #4
    zML
    Guest
    Thanks, but I figured it out I appreciated the reply, though.

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