【问题标题】:IPC in C#, sending text from one exe to another exeC#中的IPC,将文本从一个exe发送到另一个exe
【发布时间】:2012-05-12 00:21:52
【问题描述】:

我想从 WPF 应用程序的文本框中向打开的记事本发送消息。单击文本框旁边的按钮后,我希望将内容写入记事本,我的意思是。

如何在 2 个不同的应用程序之间发送消息?

【问题讨论】:

  • 你假设记事本已经打开了吗?
  • 谢谢,假设它是开放的。
  • 这应该可以帮助您入门:stackoverflow.com/questions/6604070/…
  • 我只是把这些东西搁置了几个月,现在我对它们简直是个白痴。谢谢大家。
  • 请确定您的问题是“如何将文本发送到记事本”或“如何进行 IPC”。 (旁注:考虑删除您的 cmets 并将它们合并到问题中)。

标签: c# wpf


【解决方案1】:
[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);
    }
}

【讨论】:

    【解决方案2】:

    要在您控制的两个应用程序之间发送数据,您可以使用NamedPipeClientStreamNamedPipeServerStream

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-04
      • 2015-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多