Results 1 to 7 of 7

Thread: Retreiving text from a application???

  1. #1

    Thread Starter
    Addicted Member mandark's Avatar
    Join Date
    Oct 2002
    Posts
    188

    Question Retreiving text from a application???

    Hello,

    I have an application with three text boxes, of which i need to get the text value of the third text box.

    I am using 'FindWindowEx' API get the handle to the textbox
    and 'SendMessageStr' API to retrieve the text.

    I am able to retrieve the text of the first textbox. But, not of the remaining textboxes as the class name of all the textboxes as the same!!!

    Can any one help me out???

    Thanx.

  2. #2
    Frenzied Member MerrionComputin's Avatar
    Join Date
    Apr 2001
    Location
    Dublin, Ireland
    Posts
    1,616
    Rather than Sendmessage you can get a textbox's text thus:
    VB Code:
    1. Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    2. Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    3.  
    4. Public Function WindowText(ByVal hwnd As Long) As String
    5.  
    6. Dim sRet As String
    7.  
    8. sRet = String$(GetWindowTextLength(hwnd),0)
    9.  
    10. If GetWindowText(hwnd, sRet, Len(sRet)) Then
    11.     WindowText = sRet
    12. End If
    13.  
    14. End Function

    To get all the textboxes, find the parent window and cycle through all it's child windows with GetWindow API call.

    Hope this helps,
    Duncan
    ----8<---------------------------------------
    NEW - The .NET printer queue monitor component
    ----8<---------------------------------------
    Now with Examples of use

  3. #3

    Thread Starter
    Addicted Member mandark's Avatar
    Join Date
    Oct 2002
    Posts
    188
    Thanx MerrionComputin,

    One more question, how do I cycle through the child windows of an application?

    An example would be of great help!

    Mandark

  4. #4
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    VB Code:
    1. 'in a module
    2.  
    3. Public Declare Function EnumChildWindows Lib "user32" _
    4. (ByVal hwndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    5.  
    6.  
    7. Private Sub CycleChildWindows(ByVal hwndParent As Long)
    8.     EnumChildWindows hwndParent, AddressOf EnumChildProc, ByVal 0&
    9. End Sub
    10.  
    11. Public Function EnumChildProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    12.     'print the child window
    13.     Debug.Print hwnd
    14.     'continue enumeration
    15.     EnumChildProc = 1
    16. End Function

  5. #5
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378

    Unhappy

    hi, i am trying the same thing but I am actually facing a problem. I can only get the values of the Textboxes on the other app for the first time that the other app is loaded. That is if I change the values in the textboxes my app wont detect the changes when I call GetWindowText again. It will continue to give me the previous value of the textboxes. Any idea why this is hapenning?

    thanx
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

  6. #6
    PowerPoster
    Join Date
    Aug 2000
    Location
    India
    Posts
    2,288
    Try using this code instead:
    VB Code:
    1. Private Declare Function SendMessageStr Lib "user32" Alias _
    2. "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
    3. ByVal wParam As Long, ByVal lParam As String) As Long
    4.  
    5. Private Const WM_GETTEXT = &HD
    6. Private Const WM_GETTEXTLENGTH = &HE
    7.  
    8. Dim lngTextLen As Long
    9. Dim strText As String
    10. lngTextLen = SendMessageStr(hwndTextBox, WM_GETTEXTLENGTH, 0&, 0&)
    11. strText = Space(lngTextLen + 1)
    12. SendMessageStr hwndTextBox, WM_GETTEXT, lngTextLen + 1, strText

  7. #7
    Hyperactive Member vbud's Avatar
    Join Date
    Jan 2002
    Location
    Mru 20 17S, 57 33E Goal: Get out of the BOX Status: In The Shadows!!! Target Posts: 3,000,000,000
    Posts
    378
    Thanx amitabh, the code you posted above has solved my problem.
    >!v!<
    Free your mind, stop thinking
    http://inspirone.blogspot.com

    Please rate this post if it helped you

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