Hello this is my first posting here. I have read numerous postings but this is my first contribution.

I am trying to use Sendmessage to send a string of text from one application to another. I have created a sandbox to work out the details.

I have used the “Notepad” example and I have gotten that to function.

This is what I have that works.


Code:
Public Class Xnutalk

   
    Private Declare Function SendMessageByString Lib "user32.dll" Alias "SendMessageA"_
    (ByVal hwnd As IntPtr, ByVal uMsg As Int32, ByVal wParam As IntPtr, ByVal lParam As String) As Integer

    Private Const WM_SETTEXT As Int32 = &HC
   
    Private Const WM_GETTEXTLENGTH As Int32 = &HE

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"_ 
    (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA"_
    (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr


    Public Function GetHandle(ByVal ClassName As String) As IntPtr

        Dim hwnd As IntPtr = FindWindow(ClassName, Nothing) 

        hwnd = FindWindowEx(hwnd, IntPtr.Zero, Nothing, "Xnu talk client")

        If (Not hwnd.Equals(IntPtr.Zero)) Then
            Return hwnd
        Else
            Return IntPtr.Zero
        End If
    End Function


    Sub SetNewText(ByVal hwnd As IntPtr, ByVal txt As String)
        If (Not hwnd.Equals(IntPtr.Zero)) Then
            
            Call SendMessageByString(hwnd, WM_SETTEXT, IntPtr.Zero, txt)
        End If
    End Sub


    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim khwnd As IntPtr
 
        khwnd = GetHandle("xnutalk client")

        SetNewText(khwnd, "Hello")

 
    End Sub
Now what I am trying to do is modify it so instead of changing the title bar, it adds the text, in the example “Hello”, to a TextBox inside the Window. I have not been able to figure that out.

I have tried many permutations of this and I think I am staring at trees looking for a forest.

Here is what I have tried:
Code:
Public Class Xnutalk

   
    Private Declare Function SendMessageByString Lib "user32.dll" Alias "SendMessageA"_
    (ByVal hwnd As IntPtr, ByVal uMsg As Int32, ByVal wParam As IntPtr, ByVal lParam As String) As Integer

    Private Const WM_SETTEXT As Int32 = &HC
   
    Private Const WM_GETTEXTLENGTH As Int32 = &HE

    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA"_ 
    (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA"_
    (ByVal hWnd1 As IntPtr, ByVal hWnd2 As IntPtr, ByVal lpsz1 As String, ByVal lpsz2 As String) As IntPtr


    Public Function GetHandle(ByVal ClassName As String) As IntPtr

        Dim hwnd As IntPtr = FindWindow(ClassName, Nothing) 

        hwnd = FindWindowEx(hwnd, IntPtr.Zero, Nothing, "chatbox")

        If (Not hwnd.Equals(IntPtr.Zero)) Then
            Return hwnd
        Else
            Return IntPtr.Zero
        End If
    End Function


    Sub SetNewText(ByVal hwnd As IntPtr, ByVal txt As String)
        If (Not hwnd.Equals(IntPtr.Zero)) Then
            
            Call SendMessageByString(hwnd, WM_SETTEXT, IntPtr.Zero, txt)
        End If
    End Sub


    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim khwnd As IntPtr
 
        khwnd = GetHandle("xnutalk client")

        SetNewText(khwnd, "Hello")

 
    End Sub
Where chatbox is the name of the box in question.

Does anyone have any ideas?