1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public partial class Form1 : Form
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public Form1()
{
InitializeComponent();
}
private void BtnSendMsg_Click(object sender, EventArgs e)
{
string message = "nicolas is good";
Byte[] bytes = new Byte[message.Length];
bytes = Encoding.ASCII.GetBytes(message);
IntPtr data = Marshal.AllocCoTaskMem(message.Length);
Marshal.Copy(bytes, 0, data, message.Length);
SendMessage(this.Handle, 0x400, data, (IntPtr)message.Length);
Marshal.FreeCoTaskMem(data);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == 0x400)
{
string result = Marshal.PtrToStringAnsi(m.WParam, (int)m.LParam);
MessageBox.Show("J'ai recu le message : " + result);
}
}
} |
Partager