Form中有两个Button:button1和button2,按下button2后会给button1发送一个click消息
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hwnd, int wmsg, IntPtr wparam, IntPtr lparam);
private void button2_Click(object sender, EventArgs e)
{
IntPtr hwnd_win;
IntPtr hwnd_button;
const int bm_click = 0x00f5;
Message msg = Message.Create(this.button1.Handle, bm_click, new IntPtr(0), new IntPtr(0));
PostMessage(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
Windows Mobile中
using Microsoft.WindowsCE.Forms;
[DllImport("coredll.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr PostMessage(IntPtr hwnd, int wmsg, IntPtr wparam, IntPtr lparam);
本文介绍了一种在Windows应用程序中通过编程方式模拟按钮点击的方法。利用PostMessage函数向目标按钮发送click消息,实现button2点击时触发button1的点击事件并关闭窗口。文章提供了具体的代码示例。
6789

被折叠的 条评论
为什么被折叠?



