Sending Strings to Another Application

Does anyone have any idea how i could modify the example from

in order to send strings of data to a textbox?Using Spy++ i was able to determine the app caption, and the buttons, and edits captions of the targeted app, And i have succesfully pressed a button, but i would also like to be able to put some text in a textbox.Any help would be appreciated

1

1 Answer

Assuming you have the HWND of the TextBox to which you want to send the text, this code should do it:

public partial class Form1 : Form
{
    [DllImport("user32.dll")]
    public static extern int SendMessage(IntPtr hwnd, int msg, IntPtr wParam, [MarshalAs(UnmanagedType.LPStr)] string lParam);

    private const int WM_SETTEXT = 0x000C;

    ...

    public void SetTextOnRemoteTextBox(string text)
    {
        SendMessage(textBox1.Handle, WM_SETTEXT, (IntPtr)text.Length, text);
    }

Cheers

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest