Exemple #1
0
        private void OnCommandReceived(object o, CommandEventArgs e)
        {
            //Incoming chat message (these opcodes are simply defined by the chat application).
            if (e.SentCommand.OPCode == "21")
            {
                //Client said nothing?
                if (e.SentCommand.Fields[1] == "")
                {
                    return;
                }

                //Field 0 is the senders nickname
                //Field 1 is what the sender said.

                //Stop the textbox redrawing
                txtReceived.SuspendLayout( );

                //Set the fonts
                System.Drawing.Font nickfn = new Font("Arial", 8, FontStyle.Bold);
                System.Drawing.Font chatfn = new Font("Arial", 8, FontStyle.Regular);

                if (e.SentCommand.Fields[0] != txtNickName.Text)
                {
                    txtReceived.AppendTextAsRtf(e.SentCommand.Fields[0] + "> ", nickfn, RtfColor.Blue);
                }
                else
                {
                    txtReceived.AppendTextAsRtf(e.SentCommand.Fields[0] + "> ", nickfn, RtfColor.Red);
                }

                txtReceived.AppendTextAsRtf(e.SentCommand.Fields[1] + "\r\n", chatfn, RtfColor.Black);

                //Make sure the recieved textbox doesnt get too big
                if (txtReceived.Text.Length > 2000)
                {
                    txtReceived.Select(0, 500);
                    txtReceived.SelectedText = ".";
                }

                //Application.DoEvents( );
                txtReceived.Select(txtReceived.Text.Length, 0);
                txtReceived.ScrollToCaret( );

                //Resume redraw
                txtReceived.ResumeLayout(true);

                //Flash window
                if (chkFlashing.Checked)
                {
                    FLASHWINFO finfo = new FLASHWINFO();
                    finfo.cbSize    = (uint)System.Runtime.InteropServices.Marshal.SizeOf(finfo);
                    finfo.hwnd      = this.Handle;
                    finfo.uCount    = 600;
                    finfo.dwTimeout = 400;
                    finfo.dwFlags   = PInvoke.FLASHW_TRAY | PInvoke.FLASHW_TIMER | PInvoke.FLASHW_TIMERNOFG;

                    if (this.WindowState == FormWindowState.Minimized)
                    {
                        PInvoke.FlashWindowEx(ref finfo);
                    }
                }
            }

            //Connection or disconnection of a user
            if (e.SentCommand.OPCode == "22")
            {
                //Field 0 is the users name
                //Field 1 is 0 for disconnected, or 1 for connected

                //Stop the textbox redrawing
                txtReceived.SuspendLayout( );

                System.Drawing.Font chatfn = new Font("Arial", 8, FontStyle.Regular);
                if (e.SentCommand.Fields[1] == "0")
                {
                    txtReceived.AppendTextAsRtf("*** " + e.SentCommand.Fields[0] + " disconnected.\r\n", chatfn, RtfColor.Green);
                }
                else
                {
                    txtReceived.AppendTextAsRtf("*** " + e.SentCommand.Fields[0] + " connected.\r\n", chatfn, RtfColor.Green);
                }

                //Make sure the recieved textbox doesnt get too big
                if (txtReceived.Text.Length > 2000)
                {
                    txtReceived.Select(0, 500);
                    txtReceived.SelectedText = ".";
                }

                //Application.DoEvents( );
                txtReceived.Select(txtReceived.Text.Length, 0);
                txtReceived.ScrollToCaret( );

                //Resume redraw
                txtReceived.ResumeLayout(true);
            }

            //User list
            if (e.SentCommand.OPCode == "23")
            {
                lstUsers.Items.Clear( );
                for (int i = 0; i < e.SentCommand.Fields.Length; i++)
                {
                    lstUsers.Items.Add(e.SentCommand.Fields[i]);
                }
            }
        }
Exemple #2
0
 public static extern Int16 FlashWindowEx(ref FLASHWINFO pwfi);