Exemplo n.º 1
0
        protected override void DefWndProc(ref Message m)
        {
            if (m.Msg == Windows.WM_COPYDATA)
            {
                COPYDATASTRUCT cds    = new COPYDATASTRUCT();
                Type           mytype = cds.GetType();
                cds = (COPYDATASTRUCT)m.GetLParam(mytype);      //当前的消息

                byte[] bufs = new byte[cds.cbData];             //注意,将结构体的成员单个处理再使用
                Marshal.Copy(cds.lpData, bufs, 0, bufs.Length); //复制消息

                GameMessageData MessageData = new GameMessageData();
                MessageData.buffer = bufs;
                MessageData.type   = cds.dwData;

                AddPackets(MessageData);
            }
            base.DefWndProc(ref m);
        }
Exemplo n.º 2
0
        private void AddPackets(GameMessageData Data)
        {
            try
            {
                GamePacketTypes info = new GamePacketTypes();
                BinaryReader    sr   = new BinaryReader(new MemoryStream(Data.buffer));
                info.length     = sr.ReadInt32();
                info.timestamp  = sr.ReadUInt32();
                info.identifier = sr.ReadUInt16();

                if (Data.type == 0)
                {
                    if (checkBox2.Checked)
                    {
                        if (checkBox4.Checked)
                        {
                            foreach (string s in listBox2.Items)
                            {
                                ushort i = Convert.ToUInt16(s, 16);
                                if (i == info.identifier)
                                {
                                    return;
                                }
                            }

                            ListViewItem lv = listView1.Items.Add(Data.type.ToString());
                            lv.SubItems.Add(BytesToString(Data.buffer));
                            lv.SubItems.Add(String.Format("{0:X4}", info.identifier));
                        }
                        else
                        {
                            ListViewItem lv = listView1.Items.Add(Data.type.ToString());
                            lv.SubItems.Add(BytesToString(Data.buffer));
                            lv.SubItems.Add(String.Format("{0:X4}", info.identifier));
                        }
                    }
                }
                else
                {
                    if (checkBox1.Checked)
                    {
                        if (checkBox3.Checked)
                        {
                            foreach (string s in listBox1.Items)
                            {
                                ushort i = Convert.ToUInt16(s, 16);
                                if (i == info.identifier)
                                {
                                    return;
                                }
                            }

                            ListViewItem lv = listView1.Items.Add(Data.type.ToString());
                            lv.SubItems.Add(BytesToString(Data.buffer));
                            lv.SubItems.Add(String.Format("{0:X4}", info.identifier));
                        }
                        else
                        {
                            ListViewItem lv = listView1.Items.Add(Data.type.ToString());
                            lv.SubItems.Add(BytesToString(Data.buffer));
                            lv.SubItems.Add(String.Format("{0:X4}", info.identifier));
                        }
                    }
                }
            }
            catch
            {
            }
        }