转自:http://blog.csdn.net/wuyazhe/archive/2010/07/05/5714741.aspx 感谢好友wuyazhe分享它在WM开发上的经验与心得 这贴很实用帮了我大忙,宣传宣传. using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; using System.Runtime.InteropServices; namespace MessagedWindowCE { public partial class Form1 : Form { [DllImport("coredll.dll")] private static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); [DllImport("coredll.dll")] private extern static int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hwnd, uint msg, uint wParam, int lParam); [DllImport("coredll.dll")] public static extern IntPtr SetWindowLong(IntPtr hwnd, int nIndex, IntPtr dwNewLong); public const int GWL_WNDPROC = (-4); public IntPtr OldProc = IntPtr.Zero; public Form1() { InitializeComponent(); } public delegate int WndProcHandler(IntPtr hwnd, uint msg, uint wParam, int lParam); WndProcHandler myproc = null; int MyWndProc(IntPtr hwnd, uint msg, uint wParam, int lParam) { if (msg == 0x410) { MessageBox.Show("yeah"); } return CallWindowProc(OldProc, hwnd, msg, wParam, lParam); } protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); myproc = new WndProcHandler(MyWndProc); OldProc = SetWindowLong(Handle, GWL_WNDPROC, Marshal.GetFunctionPointerForDelegate(myproc)); } private void button1_Click(object sender, EventArgs e) { PostMessage(Handle, 0x410, 0, 0); } } }