I have used this for Notepad but have not been able to get it to work for my app which opens in internet explorer. Not my choice I am just trying to read data from there.
Imports System.Runtime.InteropServices
Public Class Form1
Private Const WM_GETTEXT As Integer = &HD
Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, _
ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
<dllimport("user32.dll",> _
Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
ByVal childAfter As IntPtr, _
ByVal lclassName As String, _
ByVal windowTitle As String) As IntPtr
End Function
Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Hwnd As IntPtr = FindWindow(Nothing, "Untitled - Notepad")
Dim Handle As IntPtr = Marshal.AllocHGlobal(100)
Dim NumText As Integer = SendMessage(Hwnd, WM_GETTEXT, 50, Handle)
Dim Text As String = Marshal.PtrToStringUni(Handle)
Label1.Text = Text
Dim ChildHandle As IntPtr = FindWindowEx(Hwnd, IntPtr.Zero, "Edit", Nothing)
Dim Hndl As IntPtr = Marshal.AllocHGlobal(200)
NumText = SendMessage(ChildHandle, WM_GETTEXT, 200, Hndl)
Text = Marshal.PtrToStringUni(Hndl)
Label2.Text = Text
End Sub
End Class