Exemple #1
0
        protected override void WndProc(ref Message m)
        {
            // MessageBox.Show("!!!!!!!!!! ",  "aaa", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            // if (m.Msg == WM_CLOSE) {
            //  MessageBox.Show("********QUIIIIIIIIIIIIIIII!!!!!!!!!! ",  "aaa", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            // }

            //if(bLoaded) {
            //if(m.Msg != 28 && m.Msg != 10 && m.Msg != 31  ) {
            //  MessageBox.Show("********QUIIIIIIIIIIIIIIII!!!!!!!!!! ", m.Msg.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Warning);

            /*
             * Debug.fTrace("********QUIIIIIIIII  " + m.Msg.ToString() + " ");
             *
             *      switch(m.Msg ) {
             *                              case 130:
             *                              case WM_DESTROY:
             *              case WM_QUIT:
             *              case WM_QUERYENDSESSION:
             *                        MessageBox.Show("!!!!!!!!!! ",  "aaa", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             *              break;
             *
             * //	}
             * //}
             */



            switch (m.Msg)
            {
            // program receives WM_COPYDATA Message from target app
            case WM_COPYDATA:
                if (m.Msg == WM_COPYDATA)
                {
                    Object thisLock = new Object();
                    lock (thisLock) {
                        //	Debug.fTrace("WM_COPYDATA ");
                        // get the data
                        R_COPYDATASTRUCT cds = new R_COPYDATASTRUCT();
                        cds = (R_COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam,
                                                                       typeof(R_COPYDATASTRUCT));

                        if (cds.cbData > 2)                                         //2 to remove carriage return
                        {
                            byte[] data = new byte[cds.cbData];
                            Marshal.Copy(cds.lpData, data, 0, cds.cbData);
                            //	data[data.Length - 1 ] = 0;
                            //	try{this.BeginInvoke((MethodInvoker)delegate { try {

                            Encoding unicodeStr     = Encoding.UTF8;                                 //Not UTF8 ?? Seem work
                            string   _sReceivedText = new string(unicodeStr.GetChars(data));
                            _sReceivedText = _sReceivedText.Substring(0, _sReceivedText.Length - 2);
                            //	TraceManager.Add("****************" + _sReceivedText);

                            /*
                             *                                       myQ.Enqueue(_sReceivedText );
                             *                                       Queue mySyncdQ = Queue.Synchronized( myQ );
                             *                                       Empty.SafeInvoke(delegate {  //Not sure
                             *                                      string _sReceived = (string)mySyncdQ.Dequeue();
                             *      Empty.fRecewiveMsg(_sReceived);
                             */
                            fRecewiveMsg(_sReceivedText);

                            //	Output.SelectionColor = Color.Red;
                            //  Output.Text += _sReceivedText;

                            //		Output.AppendText("\r\n");

                            //});
                        }
                        m.Result = (IntPtr)1;
                    }
                }
                break;

            default:
                break;
            }
            base.WndProc(ref m);
        }