Is it possible to scrape the text from a textbox that is contained within a separate executable? I have an application that has a debug window. The debug window generates a verbose log. However, the log never is saved anywhere and can only be viewed within the app. If the app generates an exception, I'd like to email myself knowing that an exception has been generated so I can hop in and check things out. There is also a button to copy the textbox so I was thinking of using Spy++ to get the command information. However, I don't know where to go from there. Any pointers are greatly appreciated.
I'd prefer to use C# in .NET, but if I need to use C++, I will.
UPDATE:
Based on the comments, I've tried doing the following:
Private Declare Function GETWINDOWTEXT Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Integer) As Integer
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindow As String) As IntPtr
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Integer, ByVal hWnd2 As Integer, ByVal lpsz1 As String, ByVal lpsz2 As String) As Integer
Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
Private Const WM_GETTEXT As Short = &HDS
Private Const WM_GETTEXTLENGTH As Short = &HES
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim hwnd As Integer = FindWindowEx(0, 0, "MyAppForm", "Hello World")
If Not hwnd = 0 Then
SetForegroundWindow(hwnd)
'Dim LabelEx As Integer = FindWindowEx()
Dim TextBoxEx As Integer = FindWindowEx(hwnd, 0, "MyAppTextBox", vbNullString)
Dim txtLength As Long = SendMessage(TextBoxEx, WM_GETTEXTLENGTH, CInt(0), CInt(0)) + 1
Dim txtBuff As String = Space(txtLength)
Dim txtValue As Long = SendMessage(TextBoxEx, WM_GETTEXT, txtLength, txtBuff)
MsgBox(txtBuff)
End If
End Sub
However, I can't seem to find the handle of the textbox control. When I enumerate all of the windows, I only see one TextBox object, but I see the parent multiple times throughout the enumeration. How can I get the pointers to the controls within the window?
UPDATE 2:
I've uploaded a sample Windows app to show the type of app I'm trying to get access to. I'm trying to get the values of both labels in addition to the textbox. The textbox is the most important. The sample Win app is here: http://www.mediafire.com/file/172r2xapj7p4f2f/StatusSimulator.zip