wince要实现消息接收需要继承Microsoft.WindowsCE.Forms.MessageWindow类
public class CustomMessageWindow : Microsoft.WindowsCE.Forms.MessageWindow
{
[DllImport("coredll.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("coredll.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern int RegisterWindowMessage(string lpString);
/// <summary>
/// </summary>
/// <param name="HWnd"> hWnd:其窗口程序将接收消息的窗口的句柄。如果此参数为HWND_BROADCAST,则消息将被发送到系统中所有顶层窗口,
/// 包括无效或不可见的非自身拥有的窗口、被覆盖的窗口和弹出式窗口,但消息不被发送到子窗口。</param>
/// <param name="Msg">Msg:指定被发送的消息。</param>
/// <param name="WParam">wParam:指定附加的消息特定信息。</param>
/// <param name="LParam">IParam:指定附加的消息特定信息。</param>
/// <returns></returns>
[DllImport("coredll.dll", SetLastError = true)]
public static extern int SendMessage(IntPtr HWnd, int Msg, int WParam, int LParam);
public static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
public static int CE_Send = RegisterWindowMessage("PdaEnableModule_CE_Send");//消息ID
//form1发送
//HWND_BROADCAST 发送给所有窗体
//CE_Send 自定义消息id
//CurrentModule 附加的消息信息
SendMessage(CustomMessageWindow.HWND_BROADCAST, CE_Send, 0, (int)CurrentModule);//发送消 息给另一进程窗体
//form2 接收
/// <summary>
///
/// </summary>
/// <param name="m"></param>
protected override void WndProc(ref Microsoft.WindowsCE.Forms.Message m)
{
try
{
if (m.Msg == CE_Send)//接受指定的消息
{
CustomMessageWindow.SendMessage(CustomMessageWindow.HWND_BROADCAST, CustomMessageWindow.CE_R, 0, (int)CurrentModule);//发送消 息给另一进程窗体
}
}
catch
{
}
}
}