无法在c#.net中接收窗口消息
我想向已在运行的其他进程发送消息。怎么了。。。?为什么我不能接收消息 我的发件人代码如下无法在c#.net中接收窗口消息,c#,.net,window,C#,.net,Window,我想向已在运行的其他进程发送消息。怎么了。。。?为什么我不能接收消息 我的发件人代码如下 public partial class RegisterWindowMessage : Form { [DllImport("User32.dll", EntryPoint = "SendMessage")] //private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, I
public partial class RegisterWindowMessage : Form
{
[DllImport("User32.dll", EntryPoint = "SendMessage")]
//private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
private static extern int SendMessage(IntPtr hWnd, int Msg, string s, int i);
const int WM_SETTEXT = 0X000C;
public RegisterWindowMessage()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Process[] procs = Process.GetProcesses();
foreach (Process p in procs)
{
if (p.ProcessName.Equals("TaskScheduling"))
{
IntPtr hWnd = p.MainWindowHandle;
Thread.Sleep(1000);
SendMessage(hWnd, WM_SETTEXT, "This is the new Text!!!", 0);
MessageBox.Show("Inside");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
}
}
我的接收代码是
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
}
private void frmReceiver_KeyDown(object sender, KeyEventArgs e)
{
// this.lsvMsgList.Items.Add(e.KeyValue.ToString());
}
protected override void WndProc(ref Message m)
{
MessageBox.Show(m.Msg.ToString());
MessageBox.Show(m.LParam.ToString());
MessageBox.Show(m.WParam.ToString());
if (m.LParam.ToInt32() == 1)
{
}
else
{
base.WndProc(ref m);
}
}
}
我想知道为什么我不能接收消息。让我知道我错在哪里看起来
Form1
不是MainWindowHandle
。您可以尝试EnumWindows
枚举所有窗口,或注册新消息并使用广播。能否提供示例代码