Results 1 to 14 of 14

Thread: Visual Basic Get Text of Another Window's TextBox

Hybrid View

  1. #1
    New Member
    Join Date
    Jul 2008
    Posts
    7

    Re: Visual Basic Get Text of Another Window's TextBox

    Ok, i think ive found the problem.
    The "Edit" class is actually a child of a class called "MDINFO"

    so, i think i have to modify to code to first find the main parent = "Brwindowclass" - current code does this
    second, it must connect to the child of Brwindowclass = "MDINFO" - current code does this

    but now 3rd step: how do I connect and retrieve the text of the child of MDINFO, called "edit"?

    Ive tried this but it doesnt work.

    vb Code:
    1. Imports System.Runtime.InteropServices
    2. Public Class Form1
    3.     Private Const WM_GETTEXT As Integer = &HD
    4.     Declare Auto Function SendMessage Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal msg As Integer, _
    5.     ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
    6.     <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
    7.     Private Shared Function FindWindowEx(ByVal parentHandle As IntPtr, _
    8.                                          ByVal childAfter As IntPtr, _
    9.                                          ByVal lclassName As String, _
    10.                                          ByVal windowTitle As String) As IntPtr
    11.     End Function
    12.  
    13.     Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    14.  
    15.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    16.         'Find the running notepad window
    17.         Dim Hwnd As IntPtr = FindWindow("BRWindowClass", Nothing)
    18.  
    19.         'Alloc memory for the buffer that recieves the text
    20.         Dim Handle As IntPtr = Marshal.AllocHGlobal(100)
    21.  
    22.         'send WM_GWTTEXT message to the notepad window
    23.         Dim NumText As Integer = SendMessage(Hwnd, WM_GETTEXT, 50, Handle)
    24.  
    25.         'copy the characters from the unmanaged memory to a managed string
    26.         Dim Text As String = Marshal.PtrToStringUni(Handle)
    27.  
    28.         'Display the string using a label
    29.         Label1.Text = Text
    30.  
    31.         'Find the Edit control of the Running Notepad
    32.         Dim ChildHandle As IntPtr = FindWindowEx(Hwnd, IntPtr.Zero, "MDIClient", Nothing)
    33.         Dim Childhandle2 As IntPtr = FindWindowEx(ChildHandle, IntPtr.Zero, "Edit", Nothing)
    34.  
    35.  
    36.         'Alloc memory for the buffer that recieves the text
    37.         Dim Hndl As IntPtr = Marshal.AllocHGlobal(200)
    38.  
    39.         'Send The WM_GETTEXT Message
    40.         NumText = SendMessage(Childhandle2, WM_GETTEXT, 200, Hndl)
    41.  
    42.         'copy the characters from the unmanaged memory to a managed string
    43.         Text = Marshal.PtrToStringUni(Hndl)
    44.  
    45.         'Display the string using a label
    46.         TextBox1.Text = Text
    47.  
    48.     End Sub
    49. End Class
    Last edited by neoxyn; Mar 26th, 2010 at 11:39 AM.

  2. #2
    Lively Member C0der's Avatar
    Join Date
    Mar 2010
    Location
    Somewhere in Internet
    Posts
    113

    Re: Visual Basic Get Text of Another Window's TextBox

    Use any API-Spy utility to spy on that area of the Edit window.

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