2

I would like to send a message from a WPF application's textbox to an open notepad. After I click the button next to the the textbox, I would like the content is written into the notepad, I mean.

How can I send messages between 2 different applications ?

Pevus
  • 163
  • 4
  • 10

2 Answers2

2
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

private static void DoSendMessage(string message)
{
    Process notepad = Process.Start(new ProcessStartInfo("notepad.exe"));
    notepad.WaitForInputIdle();

    if (notepad != null)
    {
        IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), "Edit", null);
        SendMessage(child, 0x000C, 0, message);
    }
}
Nick Sinas
  • 2,594
  • 11
  • 42
  • 51
1

For sending data between two applications you control, you could use NamedPipeClientStream and NamedPipeServerStream

tom502
  • 691
  • 1
  • 5
  • 19