Results 1 to 2 of 2

Thread: Getting Text inside a window

  1. #1

    Thread Starter
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Use the FindWindow API to get the handle of the window then use the following function to retrieve the text:

    VB Code:
    1. Public Declare Function FindWindow Lib "user32" &_
    2. Alias "FindWindowA" (ByVal lpClassName As String, ByVal &_
    3. lpWindowName As String) As Long
    4. Public Declare Function FindWindowEx Lib "user32" &_
    5. Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As &_
    6.  Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    7.  
    8. Public Function GetText(Window As Long) As String
    9. Dim Cursor As String, Text As Long
    10.   Text& = SendMessage(Window&, WM_GETTEXTLENGTH, 0&, 0&)
    11.   Cursor$ = String(Text&, 0&)
    12.   Call SendMessageByString(Window&, WM_GETTEXT, Text& + 1, Cursor$)
    13.   GetText$ = Cursor$
    14. End Function
    My evil laugh has a squeak in it.

    kristopherwilson.com

  2. #2
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Here part of the code that Ive use it in my previous program and hope it make sense to you

    VB Code:
    1. Public Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    2. Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    3. Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    4.  
    5. Private Sub Command1_Click()
    6.     '//Find the Messenger Window handle
    7.     phWnd = FindWindow(0, "Messenger Service ")
    8.     'phWnd = FindWindow(0, "Project1")
    9.     If phWnd > 0 Then
    10.         '//Find the Static Window handle
    11.         EnumChildWindows phWnd, AddressOf EnumChildProc, ByVal 0&
    12.     End If
    13. End Sub
    14.  
    15. Public Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
    16.     Dim tmp As String
    17.     Dim wClass As String
    18.     Dim Buff As String
    19.    
    20.     '//Get the Child Class Name
    21.     tmp = String(260, Chr(0))
    22.     GetClassName hWnd, tmp, 260
    23.     p1 = InStr(1, tmp, Chr(0), vbTextCompare)
    24.     If p1 > 0 Then
    25.         wClass = Left$(tmp, p1 - 1)
    26.         '//compare the class name
    27.         If StrComp(UCase(wClass), "STATIC", vbTextCompare) = 0 Then
    28.             '//Continue retrieve the Message
    29.             Buff = Space$(GetWindowTextLength(hWnd) + 1)
    30.             GetWindowText hWnd, Buff, Len(Buff)
    31.            
    32.             '//Display the text
    33.             Buff = Left$(Buff, Len(Buff) - 1)
    34.             MsgBox Buff
    35.  
    36.             Exit Function
    37.         End If
    38.     End If
    39.  
    40.     '//Continue enumeration
    41.     EnumChildProc = 1
    42. End Function

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