要引入动态库,同时需要自定义消息。方法也和VC中的方法差不多。
public const int WM_USER = 0x400;
public const int WM_MYBUTTONCLICK = WM_USER + 100;
[DllImport("user32",EntryPoint="SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_MYBUTTONCLICK)
{
MessageBox.Show("MyButton Click");
}
else
base.WndProc(ref m);
}
private void button1_Click(object sender, System.EventArgs e)
{
SendMessage(this.Handle, WM_MYBUTTONCLICK, 0, 0);
}