Example #1
0
        //实时获取未读消息的定时器
        private void tmMessage_Tick(object sender, EventArgs e)
        {
            Point     pp    = new Point(Cursor.Position.X, Cursor.Position.Y);                                    //获取鼠标在屏幕的坐标点
            Rectangle Rects = new Rectangle(this.Left, this.Top, this.Left + this.Width, this.Top + this.Height); //存储当前窗体在屏幕的所在区域

            if ((this.Top < 0) && PublicClass.PtInRect(ref Rects, pp))                                            //当鼠标在当前窗体内,并且窗体的Top属性小于0
            {
                this.Top = 0;                                                                                     //设置窗体的Top属性为0
            }
            else
            //当窗体的上边框与屏幕的顶端的距离小于5时
            if (this.Top > -5 && this.Top < 5 && !(PublicClass.PtInRect(ref Rects, pp)))
            {
                this.Top = 5 - this.Height;                                     //将QQ窗体隐藏到屏幕的顶端
            }
            if (lvFriend.SelectedItems.Count > 0)                               //判断好友列表中有选中项
            {
                if (lvFriend.SelectedItems[0].Group == lvFriend.Groups[0])      //如果选中项属于第1组
                {
                    tsMenuDel.Visible = true;                                   //显示删除菜单
                    tsMenuAdd.Visible = false;                                  //隐藏添加好友菜单
                }
                else if (lvFriend.SelectedItems[0].Group == lvFriend.Groups[1]) //如果选中项属于第2组
                {
                    tsMenuDel.Visible = false;                                  //隐藏删除菜单
                    tsMenuAdd.Visible = true;                                   //显示添加好友菜单
                }
            }
            int messageTypeID = 1; //消息类型
            int messageState  = 1; //消息状态
            //查找未读消息对应的好友ID
            string        sql        = "select top 1 FromUserID, MessageTypeID, MessageState from tb_Message where ToUserID=" + PublicClass.loginID + " and MessageState=0";
            SqlDataReader dataReader = dataOper.GetDataReader(sql); //执行查询

            if (dataReader.Read())                                  //读取未读消息
            {
                fromUserID    = (int)dataReader["FromUserID"];      //记录消息发送者
                messageTypeID = (int)dataReader["MessageTypeID"];   //记录消息类型
                messageState  = (int)dataReader["MessageState"];    //记录消息状态
            }
            dataReader.Close();                                     //关闭读取器
            DataOperator.connection.Close();                        //关闭数据库连接
            //消息有两种类型:聊天消息、添加好友消息
            //判断消息类型,如果是添加好友消息,启动消息提醒定时器
            if (messageTypeID == 2 && messageState == 0)
            {
                SoundPlayer player = new SoundPlayer("system.wav"); //系统消息提示
                player.Play();                                      //播放指定声音文件
                tmAddFriend.Start();                                //启动消息提醒定时器
            }
            //如果是聊天消息,启动聊天定时器,使好友头像闪烁
            else if (messageTypeID == 1 && messageState == 0)
            {
                //获取消息发送者的ID
                sql          = "select HeadID from tb_User where ID=" + fromUserID;
                friendHeadID = dataOper.ExecSQL(sql);//设置发消息好友的头像ID
                //如果发消息的人不在好友列表中,将其添加到陌生人列表中
                if (!HasShowUser(fromUserID))
                {
                    UpdateStranger(fromUserID);                  //显示陌生人列表
                }
                SoundPlayer player = new SoundPlayer("msg.wav"); //聊天消息提示
                player.Play();                                   //播放指定声音文件
                tmChat.Start();                                  //启动聊天定时器
            }
        }
Example #2
0
 //拖动窗体
 private void Frm_Login_MouseDown(object sender, MouseEventArgs e)
 {
     PublicClass.ReleaseCapture();                                                                                    //用来释放被当前线程中某个窗口捕获的光标
     PublicClass.SendMessage(this.Handle, PublicClass.WM_SYSCOMMAND, PublicClass.SC_MOVE + PublicClass.HTCAPTION, 0); //向Windows发送拖动窗体的消息
 }
Example #3
0
 //关闭窗体
 public void pboxClose_Click(object sender, EventArgs e)
 {
     PublicClass.AnimateWindow(this.Handle, 800, PublicClass.AW_SLIDE + PublicClass.AW_VER_POSITIVE + PublicClass.AW_HIDE); //动画隐藏窗体
     this.FormNowState = FormState.Hide;                                                                                    //设定当前窗体的状态为隐藏
 }