IPC in C#, sending text from one exe to another exe

前端 未结 2 2120
长发绾君心
长发绾君心 2021-02-11 04:38

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 t

相关标签:
2条回答
  • 2021-02-11 05:12
    [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);
        }
    }
    
    0 讨论(0)
  • 2021-02-11 05:18

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

    0 讨论(0)
提交回复
热议问题