C# c在listview中选择进程并向其发送消息

C# c在listview中选择进程并向其发送消息,c#,listview,process,C#,Listview,Process,所以我制作了一个进程列表视图,现在我想让它成为我必须在其中选择一个进程,然后在我的case记事本中向它发送消息 如何将记事本进程声明分配给选定的listview项 以下是我目前的情况: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Tex

所以我制作了一个进程列表视图,现在我想让它成为我必须在其中选择一个进程,然后在我的case记事本中向它发送消息

如何将记事本进程声明分配给选定的listview项

以下是我目前的情况:

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Management;


namespace sendMessage
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        [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);



        public void DisplayProcesses() {
            try
            {
                Process[] processList = Process.GetProcesses();

                foreach (Process proc in processList)
                {
                    ListViewItem item = new ListViewItem(proc.ProcessName);
                    item.SubItems.Add(proc.ProcessName);
                    item.Tag = proc;
                    listView1.Items.Add(item);
                }
            }
            catch(Exception ex) {
                Console.WriteLine(ex);
            }
        }

        private static void DoSendMessage(string message)
        {
            Process notepad = new Process();
            notepad.ProcessName=

            if (notepad != null)
            {
                IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), "Edit", null);
                SendMessage(child, 0x000C, 0, message);
            }
            else {
                MessageBox.Show("No process...");
            }
        }


        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("TextBox is empty");
            }
            else {
                DoSendMessage(textBox1.Text);
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            DisplayProcesses();
        }
    }
}

记事本的输入是标准输入。因此,您需要使用流程的标准输出与记事本进行通信。我希望这样,以便我可以从lsitview中选择它,以防我有多个记事本流程,并且我希望选择一个特定的流程,我不知道您的问题是什么。粘贴相关的代码,而不是粘贴所有代码。是否有一个特定的原因可以解释为什么使用标记不起作用?在DoSendMessage中,我希望将进程记事本分配给listview中选定的itemprocess。这在我的问题中说得很清楚,你需要为每个记事本应用程序有一个单独的进程,除非你计划连接一个作为流类(管道)的连接,然后断开每个应用程序的连接。对于多个连接,我建议将您的进程放入一个类中,这样您就可以为每个连接拥有一个类的多个实例。