示例#1
0
        //重写窗体的消息处理函数DefWndProc,从中加入自己定义消息 MYMESSAGE 的检测的处理入口
        protected override void DefWndProc(ref Message m)
        {
            messageLock = new Object();//实现临界区同步锁
            lock (messageLock)
            {
                switch (m.Msg)
                {
                //接收自定义消息CONTENTMESSAGE,一次接收的WITS数据并显示其参数
                case CONTENTMESSAGE:
                    WitsTransmission.TCPUtil.SendDataStruct contentStruct = new WitsTransmission.TCPUtil.SendDataStruct(); //这是创建自定义信息的结构
                    Type mytype = contentStruct.GetType();
                    contentStruct     = (WitsTransmission.TCPUtil.SendDataStruct)m.GetLParam(mytype);                      //这里获取的就是作为LParam参数发送来的信息的结构
                    m_contentWitsData = contentStruct.lpData;                                                              //显示收到的自定义信息
                    //启动解析WITS帧线程
                    ParseWitsData(m_contentWitsData);
                    //启动写库线程
                    m_isWriteDB = true;
                    if (!m_writeDBThread.IsAlive)
                    {
                        m_writeDBThread.Start();
                    }
                    break;

                default:
                    base.DefWndProc(ref m);
                    break;
                }
            }
            messageLock = null;
        }
示例#2
0
        private static extern int SendMessage(

            IntPtr hWnd,              // 信息发住的窗口的句柄

            int Msg,                  // 消息ID

            int wParam,               // 参数1

            ref SendDataStruct lParam // 参数2   [MarshalAs(UnmanagedType.LPTStr)]StringBuilder lParam

            );