⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.~pas

📁 一个QQ的界面源码
💻 ~PAS
📖 第 1 页 / 共 4 页
字号:
         Udp.RemoteHost:=FromIP;
         Udp.RemotePort:=Port;
         Udp.SendStream(MyStream);
      finally
         MyStream.Free;
      end;
//判断是否为好友,是则将其头像颜色改为彩色
//这一部分特别容易出错,下面的做法是否可靠还得经过长期测试
      DMShare.TblFriends.First;
      if DMShare.TblFriends.Locate('QQNumber',aMsg[2],[]) then
      begin
      //在系统托盘显示上线通知
         if bOnlineInfo then
         begin
            TrayIcon.ShowBalloonHint(
                  '上线通知',
                  '〖'+DMShare.TblFriends.FieldValues['UserName']+'〗'+'上线啦……',
                  bitInfo,
                  5);
         end;

         sndPlaySound(Pchar(ExtractFilePath(Application.ExeName)+'sound\online.wav'),SND_ASYNC);
         //在好友列表中查找(这里的做法效率不高,何是改进?)
         for i := 0 to SideBar.Groups[0].ItemCount-1 do
         begin
            if SideBar.Groups[0].Items[i].Tag=StrToInt(aMsg[2]) then
            begin
               SideBar.Groups[0].Items[i].LargeImage:=StrToInt(aMsg[4]);
               SideBar.Groups[0].Items[i].SmallImage:=StrToInt(aMsg[4]);
               SideBar.Groups[0].Items[i].Index:=0;
               Abort;
            end;
         end;
         //在黑名单中查找
         for i := 0 to SideBar.Groups[2].ItemCount-1 do
         begin
            if SideBar.Groups[2].Items[i].Tag=StrToInt(aMsg[2])
               and DMShare.TblFriends.FieldValues['IsBaddy'] then
            begin
               SideBar.Groups[2].Items[i].LargeImage:=StrToInt(aMsg[4]);
               SideBar.Groups[2].Items[i].SmallImage:=StrToInt(aMsg[4]);
               SideBar.Groups[2].Items[i].Index:=0;
               Abort;
            end;
         end;
      end;
      Exit;
   end;//end of Msg is 'ONL'

//判断是否为“查找好友“信息
   if aMsg[1]='FIN' then
   begin
      MyStream := TMemoryStream.Create;
      try
//         sMsg:='IMO'+'*'+sQQNumber+'*'+sUserName+'*'+IntToStr(iFaceID)+'*';
         sMsg:='YFM'+'*'+sQQNumber+'*'+sUserName+'*'+IntToStr(iFaceID)+'*';
         MyStream.Write(sMsg[1],Length(sMsg));
         Udp.RemoteHost:=FromIP;
         Udp.LocalPort:=8088;
         Udp.RemotePort:=8088;
         Udp.SendStream(MyStream);
      finally
         Mystream.Free;
      end;
      Exit;
   end;//end of Msg is 'FIN'

(*//判断是否为“在线通知”信息 或 是否为“查找好友“的返回在线信息
   if aMsg[1]='IMO' then
   begin
      DMShare.TblFriends.First;
      bIsInDB:=DMShare.TblFriends.Locate('QQNumber',aMsg[2],[]);
      Hnd:=FindWindow('TFrmFindFriends','查找用户');

      if bIsInDB and (Hnd=0) then
      begin
      //在此添加更改好友头像为 彩色 的功能代码
         sndPlaySound(Pchar(ExtractFilePath(Application.ExeName)+'sound\online.wav'),SND_ASYNC);
         //在好友列表中查找(这里的做法效率不高,何是改进?)
         for i := 0 to SideBar.Groups[0].ItemCount-1 do
         begin
            if SideBar.Groups[0].Items[i].Tag=StrToInt(aMsg[2]) then
            begin
               SideBar.Groups[0].Items[i].LargeImage:=StrToInt(aMsg[4]);
               SideBar.Groups[0].Items[i].SmallImage:=StrToInt(aMsg[4]);
               SideBar.Groups[0].Items[i].Index:=0;
               Abort;
            end;
         end;
         //在黑名单中查找
         for i := 0 to SideBar.Groups[2].ItemCount-1 do
         begin
            if SideBar.Groups[2].Items[i].Tag=StrToInt(aMsg[2])
               and DMShare.TblFriends.FieldValues['IsBaddy'] then
            begin
               SideBar.Groups[2].Items[i].LargeImage:=StrToInt(aMsg[4]);
               SideBar.Groups[2].Items[i].SmallImage:=StrToInt(aMsg[4]);
               SideBar.Groups[2].Items[i].Index:=0;
               Abort;
            end;
         end;
      end;
//如果不为好友并且查找窗体不存在时,将它加入在线列表框
      if (not bIsInDB) and (Hnd<>0) then
      begin
         FrmFindFriends.FriendsLstBox.AddItem(aMsg[3],StrToInt(aMsg[4]));
         FrmFindFriends.FriendsLstBox.ItemIndex:=0;
         i:=FrmFindFriends.FriendsLstBox.Items.Count-1;
         aFndLst[i]:=aMsg[2]+'*'+aMsg[3]+'*'+aMsg[4]+'*'+FromIP+'*';
      end;
   Exit;
   end;*)

//判断是否为“在线通知”信息
   if aMsg[1]='IMO' then
   begin
      DMShare.TblFriends.First;
      if DMShare.TblFriends.Locate('QQNumber',aMsg[2],[]) then
      begin
      //在此添加更改好友头像为 彩色 的功能代码
         sndPlaySound(Pchar(ExtractFilePath(Application.ExeName)+'sound\online.wav'),SND_ASYNC);
         //在好友列表中查找(这里的做法效率不高,何是改进?)
         for i := 0 to SideBar.Groups[0].ItemCount-1 do
         begin
            if SideBar.Groups[0].Items[i].Tag=StrToInt(aMsg[2]) then
            begin
               SideBar.Groups[0].Items[i].LargeImage:=StrToInt(aMsg[4]);
               SideBar.Groups[0].Items[i].SmallImage:=StrToInt(aMsg[4]);
               SideBar.Groups[0].Items[i].Index:=0;
               Abort;
            end;
         end;
         //在黑名单中查找
         for i := 0 to SideBar.Groups[2].ItemCount-1 do
         begin
            if SideBar.Groups[2].Items[i].Tag=StrToInt(aMsg[2])
               and DMShare.TblFriends.FieldValues['IsBaddy'] then
            begin
               SideBar.Groups[2].Items[i].LargeImage:=StrToInt(aMsg[4]);
               SideBar.Groups[2].Items[i].SmallImage:=StrToInt(aMsg[4]);
               SideBar.Groups[2].Items[i].Index:=0;
               Abort;
            end;
         end;
      end;
      Abort;
   end;

//判断是是否为‘YFM’
   if (aMsg[1]='YFM') and (FindWindow('TFrmFindFriends',nil)>0) then
   begin
      DMShare.TblFriends.First;
      //如果不是已添加的好友,则将其加入“在线用户”列表
      if not DMShare.TblFriends.Locate('QQNumber',aMsg[2],[]) then
      begin
         FrmFindFriends.FriendsLstBox.AddItem(aMsg[3],StrToInt(aMsg[4]));
         FrmFindFriends.FriendsLstBox.ItemIndex:=0;
         {将在线用户信息存入数组 aFndLst}
         for i := 0 to 255 do
         begin
            if aFndLst[i]='' then
            begin
               aFndLst[i]:=aMsg[2]+'*'+aMsg[3]+'*'+aMsg[4]+'*'+FromIP+'*';
               Break;//此句不能少啊!!!
            end;
         end;
      end;
   end;

//判断是否为“下线”或“隐身”信息
   if (aMsg[1]='OFF') or (aMsg[1]='HID') then
   begin
      if not DMShare.TblFriends.Active then Exit;{此句是为屏幕退出时的出错消息}
      DMShare.TblFriends.First;
      if DMShare.TblFriends.Locate('QQNumber',aMsg[2],[]) then
      begin
      //下线通知
         if bOnlineInfo then
         begin
            TrayIcon.ShowBalloonHint(
                  '下线通知',
                  '〖'+DMShare.TblFriends.FieldValues['UserName']+'〗'+'下线啦……',
                  bitInfo,
                  5);
         end;

      //在此将好友头像改为灰色
         sndPlaySound(Pchar(ExtractFilePath(Application.ExeName)+'sound\offline.wav'),SND_ASYNC);
         //在好友列表中查找(这里的做法效率不高,何是改进?)
         for i := 0 to SideBar.Groups[0].ItemCount-1 do
         begin
            if SideBar.Groups[0].Items[i].Tag=StrToInt(aMsg[2]) then
            begin
               SideBar.Groups[0].Items[i].LargeImage:=StrToInt(aMsg[4])+85;
               SideBar.Groups[0].Items[i].SmallImage:=StrToInt(aMsg[4])+85;
               SideBar.Groups[0].Items[i].Index:=SideBar.Groups[0].ItemCount-1;
               Abort;
            end;
         end;
         //在黑名单中查找
         for i := 0 to SideBar.Groups[2].ItemCount-1 do
         begin
            if SideBar.Groups[2].Items[i].Tag=StrToInt(aMsg[2])
               and DMShare.TblFriends.FieldValues['IsBaddy'] then
            begin
               SideBar.Groups[2].Items[i].LargeImage:=StrToInt(aMsg[4])+85;
               SideBar.Groups[2].Items[i].SmallImage:=StrToInt(aMsg[4])+85;
               SideBar.Groups[2].Items[i].Index:=SideBar.Groups[2].ItemCount-1;
               Abort;
            end;
         end;
      end;
      Abort;

   end;


//判断是否为接收到”消息“,这个判断应该放在最后,在这个判断后面应该没有任何判断
   if aMsg[1]='MSG' then
   begin
      //判断对方是否为黑名单中的人,是则不去理会
      with DMShare.TblFriends do
      begin
         First;
         if Locate('QQNumber',aMsg[2],[]) then
         begin
            if FieldValues['IsBaddy'] then Abort;
         end;
      end;

//保存聊天记录
   with DMShare.TblChatLog do
   begin
      Append;
      FieldValues['QQNumber']:=aMsg[2];
      FieldValues['UserName']:=aMsg[3];
      FieldValues['IsSender']:=True;
      FieldValues['Time']:=Now;
      FieldValues['Message']:=aMsg[5];
      Post;
   end;


//如果是“离开”状态,则发送离开信息
   if bLeave then
   begin
      MyStream:=TMemoryStream.Create;
      try
         sMsg:='MSG'+'*'+sQQNumber+'*'+sUserName+'*'+IntToStr(iFaceID)+'*'+sLeaveMsg+'*';
         Mystream.Write(sMsg[1],Length(sMsg));
         Udp.LocalPort:=8088;
         Udp.RemotePort:=8088;
         Udp.RemoteHost:=FromIP;
         Udp.SendStream(MyStream);
      finally
         MyStream.Free;
      end;

   end;




{判断消息窗体是否创建,这里还要改,这样子不对地}
      for i := 0 to 254 do
      begin
         if WndRecArr[i].QQNum='' then
         begin
            WndRecArr[i].QQNum:=aMsg[2];
            WndRecArr[i].PForm:=TFrmMsg.Create(Application);
            WndRecArr[i].MyTimer:=TTimer.Create(FrmMain_QQ);
         {向OnTimer事件传递发送消息好友的QQNumber}
            sSenderQQNum:=aMsg[2];

            {设置使SideBar上头像跳动的定时器}
            WndRecArr[i].MyTimer.Interval:=400;
            WndRecArr[i].MyTimer.OnTimer:=FrmMain_QQ.MyTimer;
            WndRecArr[i].MyTimer.Tag:=StrToInt(aMsg[2]);
            WndRecArr[i].MyTimer.Enabled:=True;

            Break;//此句不能少
         end;
      end;




      //创建消息窗体,并且设置其相关属性
//      with TFrmMsg.Create(Application) do
      with WndRecArr[i].PForm do
      begin
         sndPlaySound(PChar(ExtractFilePath(Application.ExeName)+'\sound\msg.wav'),SND_ASYNC);
         Caption:='收到消息';
         LabSendTo.Caption:='消息来自:';
         LabQQNumber.Caption:=aMsg[2];{这里保存对方QQNumber,以便在回复时知道是谁发过来的}
         PnlUserName.Caption:=aMsg[3];
         BtnRevert.Enabled:=True;
         RedMsg.Text:=aMsg[5];//因为RegMsg.Text改变后,BtnSend.Enable会变成True,所以这句要放在下句上面
         BtnSend.Enabled:=False;
         RedMsg.ReadOnly:=True;
         RedMsg.Color:=clScrollBar;
//显示好友头像
      {先将头像提取出存储在硬盘上}
         MyFace:=TBitMap.Create;
         sPath:=ExtractFilePath(Application.ExeName)+'temp\';
         sBmpName:=aMsg[2]+'_1.bmp';
         if not FileExists(sPath+sBmpName) then
         begin
            DMShare.ImgLarge.GetBitmap(StrToInt(aMsg[4]),MyFace);
            MyFace.SaveToFile(sPath+sBmpName);{存储第一张图}
         end;
         sBmpName:=aMsg[2]+'_2.bmp';
         if not FileExists(sPath+sBmpName) then
         begin
            DMShare.ImgLarge.GetBitmap(StrToInt(aMsg[4])+170,MyFace);
            MyFace.SaveToFile(sPath+sBmpName);{存储第二张图}
         end;
         DMShare.ImgLarge.GetBitmap(StrToInt(aMsg[4]),ImgFace.Picture.Bitmap);
//         ImgFace.Picture.Bitmap:=MyFace;

         if (FileExists(sPath+aMsg[2]+'_1.bmp')) and
            (FileExists(sPath+aMsg[2]+'_2.bmp'))  then
         begin
            Timer.Enabled:=True;  {用定时器使好友眨眼睛}
         end;
//bautoshowmsg:=true;
      {判断是否自动弹出窗体}
         if bAutoShowMsg then
         begin
            Show;
            Update;
            BtnRevert.SetFocus;
            WndRecArr[i].QQNum:='';{此句一定要加,消息窗体一旦show,一定要释放它占用的数组空间}
         end
         else{如果不自动弹出消息窗体,则使好友头像跳动}
         begin
//////////////////////////
//在此添加头像跳动代码,用定时器
////////////////////////////


//////////////////////////////////////////
//以后再修改下面的代码,为不同好友创建不同图标在系统托盘
//////////////////////////////////////////
      {下面代码使系统托盘图标跳动}
(*            SmallFace:=TBitmap.Create;
            DMShare.ImgSmall.GetBitmap(StrToInt(aMsg[4]),SmallFace);
//            DMShare.IconList.Delete(1);
            DMShare.IconList.Insert(1,SmallFace,nil);
            TrayIcon.CycleInterval:=400;
            TrayIcon.IconList:=DMShare.IconList;
            TrayIcon.CycleIcons:=True;
*)

            TrayIcon.IconList:=DMShare.IconList;
            TrayIcon.CycleIcons:=True;

         end;

      end;

      {将收到的信息与数据库中的数据相比较,如果不同,则不同,则更新数据库中的数据,
      并且更改BtnBar上的头像和妮称}
      with DMShare.TblFriends do
      begin
         First;
         if Locate('QQNumber',aMsg[2],[]) then
         begin
            if FieldValues['UserName']<>aMsg[3] then {开始更新数据库}
            begin
               Edit;
               FieldValues['UserName']:=aMsg[3];
               Post;
            end;
            if FieldValues['FaceId']<>StrToInt(aMsg[4]) then
            begin
               Edit;
               FieldValues['FaceID']:=StrToInt(aMsg[4]);
               Post;
            end;
            if FieldValues['IP']<>FromIP then
            begin
               Edit;
               FieldValues['IP']:=FromIP;
               Post;
            end;{更新数据库完毕}
            {开始更新BtnBar上头像的caption和imagelist,其实下面的语句非常地不好
            下面的写法,不管用户信息是否更改,都要更新BtnBar上好友的头像和妮称,
            频繁地读取数据库,可能导致不稳定,何时一定要改进}
            for i := 0 to SideBar.Groups[0].ItemCount-1 do
            begin
               if SideBar.Groups[0].Items[i].Tag=StrToInt(aMsg[2]) then
               begin
                  SideBar.Groups[0].Items[i].Caption:=aMsg[3];
                  SideBar.Groups[0].Items[i].LargeImage:=StrToInt(aMsg[4]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -