Results 1 to 8 of 8

Thread: How to read text from text box in external app?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    How to read text from text box in external app?

    I already have the code which finds a particular application that is running and uses sendkeys to manipulate it and get to a specific screen within the application. Once on this particular screen, there is a textbox that immediately gets the focus and is highlighted. I want to be able to read that text value within code. Any example of how to do this would be appreciated.

    Visual Studio 2010

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to read text from text box in external app?

    you'd send a WM_GETTEXT message to the window handle which you'd get with FindWindowEx API if you search the forum for that message or that API then you'll find lots of examples.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Re: How to read text from text box in external app?

    I have done a search but can't really find anything for the situation that I have. Basically, I have a situation where I need to read the text out of the second text box on a form, or the text box that currently has the focus. None of the sample code allows you to read the text that is currently in focus or selected.

    Visual Studio 2010

  4. #4
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: How to read text from text box in external app?

    simple example

    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Debug.? GetText(Text1.hwnd)
    4.  
    5. End Sub
    6.  
    7. 'gets the text of a textbox or a caption of most controls
    8. Public Function GetText(ByVal pHwnd As Long) As String
    9.  
    10.     Dim Buffer As String, TextLength As Long
    11.  
    12.     TextLength = SendMessage(pHwnd, WM_GETTEXTLENGTH, 0&, 0&)
    13.     Buffer = String$(TextLength, 0&)
    14.     Call SendMessage(pHwnd, WM_GETTEXT, TextLength + 1, Buffer)
    15.     GetText = Buffer
    16.  
    17. End Function

  5. #5
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: How to read text from text box in external app?

    now that i read you'r 2nd post, you're wanting your code to read the text from the textbox thats in focus?

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091

    Re: How to read text from text box in external app?

    Quote Originally Posted by Billy Conner
    now that i read you'r 2nd post, you're wanting your code to read the text from the textbox thats in focus?
    Yes, exactly. How can that be done?

    Visual Studio 2010

  7. #7
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: How to read text from text box in external app?

    i assume your using sendkeys to 'navigate' this app thru its process, is it picking a random textbox on the current form, or how is that working?

    you can always use the GetFocus API call to get the current control that has focus.

  8. #8
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    Re: How to read text from text box in external app?

    if it's selected, can't you simply send a "Ctrl-C" to copy it to the clipboard?

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