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.
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.
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.
Re: How to read text from text box in external app?
simple example
VB Code:
Private Sub Form_Load()
Debug.? GetText(Text1.hwnd)
End Sub
'gets the text of a textbox or a caption of most controls
Public Function GetText(ByVal pHwnd As Long) As String
Dim Buffer As String, TextLength As Long
TextLength = SendMessage(pHwnd, WM_GETTEXTLENGTH, 0&, 0&)
Buffer = String$(TextLength, 0&)
Call SendMessage(pHwnd, WM_GETTEXT, TextLength + 1, Buffer)
GetText = Buffer
End Function
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?
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?
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.
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?