www.pudn.com > QQ_FACE.rar > main.pas


unit main; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls, Buttons, dxsbar, Menus, ImgList, NMUDP, MMSystem, 
  TimerLst, HotKeySpy, CoolTrayIcon, IniFiles; 
 
type 
{  TWndRec=record //自定义的类 
//    Hnd:THandle; 
    QQNum:string; 
    PForm:TForm; 
  end; 
} 
  TFrmMain_QQ = class(TForm) 
    PMOnline: TPopupMenu; 
    PMMain: TPopupMenu; 
    ItmOnline: TMenuItem; 
    N2: TMenuItem; 
    ItmHide: TMenuItem; 
    ItmOffline: TMenuItem; 
    ItmLeave1: TMenuItem; 
    ItmLeave2: TMenuItem; 
    ItmShowMainForm: TMenuItem; 
    N8: TMenuItem; 
    ItmSetup: TMenuItem; 
    N10: TMenuItem; 
    N11: TMenuItem; 
    N12: TMenuItem; 
    ItmExit: TMenuItem; 
    ItmLoginAgain: TMenuItem; 
    PMItem: TPopupMenu; 
    PMGroup: TPopupMenu; 
    ItmRenameGroup: TMenuItem; 
    ItmAddGroup: TMenuItem; 
    ItmDelGroup: TMenuItem; 
    ItmSendMsg: TMenuItem; 
    N16: TMenuItem; 
    ItmDelFriend: TMenuItem; 
    N23: TMenuItem; 
    ItmImgSmall: TMenuItem; 
    ItmImgLarge: TMenuItem; 
    Udp: TNMUDP; 
    Panel1: TPanel; 
    BtnChatroom: TSpeedButton; 
    BtnHomepage: TSpeedButton; 
    BtnSearch: TSpeedButton; 
    BtnMsg: TSpeedButton; 
    BtnMain: TSpeedButton; 
    BtnOnline: TSpeedButton; 
    SideBar: TdxSideBar; 
    ItmBeBaddy: TMenuItem; 
    N15: TMenuItem; 
    ItmSelfSetup2: TMenuItem; 
    ItmSysSetup: TMenuItem; 
    ItmSelfSetup: TMenuItem; 
    RxTimerList: TRxTimerList; 
    TimHideForm: TRxTimerEvent; 
    HotKeySpy1: THotKeySpy; 
    TrayIcon: TCoolTrayIcon; 
    ItmLeave3: TMenuItem; 
    ItmLeave4: TMenuItem; 
    ItmByMe: TMenuItem; 
    N1: TMenuItem; 
    procedure BtnOnlineClick(Sender: TObject); 
    procedure BtnMainClick(Sender: TObject); 
    procedure ItmExitClick(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure UDPDataReceived(Sender: TComponent; NumberBytes: Integer; 
      FromIP: String; Port: Integer); 
    function SendOnlineMessage:boolean; 
    procedure ExtractMsg(s:string); 
//    procedure IAmOnline(sMyQQNum,sMyName,sMyIP:string;iMyFaceID:integer); 
    procedure ItmImgLargeClick(Sender: TObject); 
    procedure ItmImgSmallClick(Sender: TObject); 
    procedure BtnSearchClick(Sender: TObject); 
{    procedure LstFriendsClickItem(Sender: TObject; 
      Item: TabcButtonListItem);} 
    procedure BtnBarChange(Sender: TObject); 
    procedure ItmSendMsgClick(Sender: TObject); 
    procedure FormClose(Sender: TObject; var Action: TCloseAction); 
    procedure SideBarItemClick(Sender: TObject; Item: TdxSideBarItem); 
    procedure SideBarDblClick(Sender: TObject); 
    procedure SideBarMouseDown(Sender: TObject; Button: TMouseButton; 
      Shift: TShiftState; X, Y: Integer); 
    procedure ItmSetupClick(Sender: TObject); 
    procedure ItmSelfSetupClick(Sender: TObject); 
    procedure ItmSelfSetup2Click(Sender: TObject); 
    procedure ItmSysSetupClick(Sender: TObject); 
    procedure ItmDelFriendClick(Sender: TObject); 
    procedure ItmBeBaddyClick(Sender: TObject); 
    procedure ItmRenameGroupClick(Sender: TObject); 
    procedure ItmAddGroupClick(Sender: TObject); 
    procedure ItmDelGroupClick(Sender: TObject); 
    procedure TimHideFormTimer(Sender: TObject); 
    procedure HotKeySpy1HotKeys0HotKey(Sender: TObject); 
    procedure Offline; 
    procedure ItmOfflineClick(Sender: TObject); 
    procedure ItmHideClick(Sender: TObject); 
    procedure ItmOnlineClick(Sender: TObject); 
    procedure ItmLoginAgainClick(Sender: TObject); 
    procedure ItmShowMainFormClick(Sender: TObject); 
    procedure TrayIconDblClick(Sender: TObject); 
    procedure TrayIconClick(Sender: TObject);//自定义过程 
    procedure MyTimer(Sender:TObject); 
    procedure BtnHomepageClick(Sender: TObject); 
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); 
    procedure N11Click(Sender: TObject); 
    procedure ItmLeave1Click(Sender: TObject); 
    procedure ItmLeave2Click(Sender: TObject); 
    procedure ItmLeave3Click(Sender: TObject); 
    procedure ItmLeave4Click(Sender: TObject); 
    procedure ItmByMeClick(Sender: TObject); 
    procedure N10Click(Sender: TObject);//write by Jie.Gu 
//  TStrArray = Array[1..5] of string; 
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
 
var 
  FrmMain_QQ: TFrmMain_QQ; 
  aMsg:Array[1..5] of string; 
//  WndRecArr:array of TWndRec; 
 
 
implementation 
 
uses by_user, dm_share, Var_Share, Frind_friends, msg, untSetup, login, 
  untAbout; 
 
{type 
  TWndRec=record //自定义的类 
//    Hnd:THandle; 
    QQNum:string; 
    PForm:TFrmMsg; 
  end; 
} 
var 
   bHide:boolean=False;{分辨窗体是否隐藏} 
//   WndRecArr:array of TWndRec; 
 
{$R *.dfm} 
 
//发送下线信息(自定义过程) 
procedure TFrmMain_QQ.Offline; 
var 
   sMsg:string; 
   MyStream:TMemoryStream; 
begin 
   sMsg:='OFF*'+sQQNumber+'*'; 
   MyStream := TMemoryStream.Create; 
   try 
      MyStream.Write(sMsg[1],Length(sMsg)); 
      Udp.LocalPort:=8088; 
      Udp.RemotePort:=8088; 
      Udp.RemoteHost:=GetGBIP(g_sIP); 
      Udp.SendStream(MyStream); 
   finally 
      MyStream.Free; 
   end; 
end; 
 
//分解收到的信息 
procedure TFrmMain_QQ.ExtractMsg(s:string); 
var 
   i:integer; 
   sTemp:string; 
   iTime:integer; 
   iPos:integer; 
begin 
//判断循环次数 
   sTemp:=s[1]+s[2]+s[3]; 
   if sTemp='SYS' then iTime:=2; 
   if sTemp='ONL' then iTime:=4; 
   if sTemp='OFF' then iTime:=2; 
   if sTemp='HID' then iTime:=2; 
   if sTemp='LEA' then iTime:=2; 
   if sTemp='MSG' then iTime:=5; 
   if sTemp='IMO' then iTime:=4;//改为4,原来为2 
   if sTemp='FIN' then iTime:=1; 
   if sTemp='YFM' then iTime:=4; 
//   if sTemp='ATD' then iTime:=5;//‘ATD’意为 ADD TO DATABASE,是在查找用户时,存储在线用户信息的,不属于通讯协议 
 
//开始分解 
   for i := 1 to iTime do 
   begin 
      iPos:=Pos('*',s); 
      aMsg[i]:=Copy(s,1,iPos-1); 
      Delete(s,1,iPos); 
   end; 
end; 
 
//收到ONL(上线通知)信息后,返回IMO(我在线)的信息 
{procedure TFrmMain.IAmOnline(sMyQQNum,sMyName,sMyIP:string;iMyFaceID:integer); 
begin 
   with DMShare.TblFriends do 
   begin 
      First; 
      if Locate('QQNumber',sMyQQNum,[]) then 
      begin 
         //判断用户信息,如果有改变则更新数据库 
         if FieldValues['UserName']<>sMyName then FieldValues['UserName']:=sMyName; 
         if FieldValues['IP']<>sMyIP then FieldValues['IP']:=sMyIP; 
         if FieldValues['FaceID']<>iMyFaceID then FieldValues['FaceId']:=iMyFaceID; 
      end; 
   end; 
end;} 
 
procedure TFrmMain_QQ.BtnOnlineClick(Sender: TObject); 
begin 
   PMOnline.Popup(FrmMain_QQ.Left+FrmMain_QQ.Width-25,FrmMain_QQ.Top+FrmMain_QQ.Height-5); 
end; 
 
procedure TFrmMain_QQ.BtnMainClick(Sender: TObject); 
begin 
   PMMain.Popup(FrmMain_QQ.Left+5,FrmMain_QQ.Top+FrmMain_QQ.Height-5); 
end; 
 
procedure TFrmMain_QQ.ItmExitClick(Sender: TObject); 
begin 
   Close; 
end; 
 
//发送上线信息 
function TFrmMain_QQ.SendOnlineMessage:boolean; 
var 
   MyStream:TMemoryStream; 
   sMsg:string; 
begin 
   sMsg:='ONL*'+sQQNumber+'*'+sUserName+'*'+IntToStr(iFaceID)+'*'; 
   MyStream:=TMemoryStream.Create; 
   try 
   MyStream.Write(sMsg[1],Length(sMsg)); 
   Udp.LocalPort:=8088; 
   Udp.RemotePort:=8088; 
   Udp.RemoteHost:=GetGBIP(g_sIP); 
   Udp.SendStream(Mystream); 
   Result:=True;  //这个返回值是乱定义地,事实上无法确认发送是否成功。或许以后会用到 :-) 
   finally 
      MyStream.Free; 
   end; 
end; 
 
procedure TFrmMain_QQ.FormCreate(Sender: TObject); 
var 
  i:integer; 
  NewItem:TdxSideBarItem; 
  MyIni:TIniFile; 
  StrLst:TStringList; 
begin 
   SetLength(WndRecArr,255);{分配空间,同时创建的FrmMsg应该不会超过255吧!} 
   //删除临时目录 
   if DirectoryExists(ExtractFilePath(Application.ExeName)+'temp') then 
   begin 
      Deltree(ExtractFilePath(Application.ExeName)+'temp'); 
   end; 
//再建一个TEMP目录 
   if not DirectoryExists(ExtractFilePath(Application.ExeName)+'temp') then 
   begin 
     MkDir(ExtractFilePath(Application.ExeName)+'temp'); 
   end; 
 
   TrayIcon.CycleIcons:=False; 
   TrayIcon.IconList:=nil; 
//   DMShare.IconList.GetIcon(0,TrayIcon.Icon); 
 
   FrmMain_QQ.Caption:=sUserName; 
   FrmMain_QQ.Width:=100; 
   SideBar.LargeImages:=DMShare.ImgLarge; 
   SideBar.SmallImages:=DMShare.ImgSmall; 
 
   FrmMain_QQ.SendOnlineMessage;//发送上线信息 
 
//从数据库中读取好友信息,并添加在BtnBar中 
   with DMShare.TblFriends do 
   begin 
      if Active then First; 
      while not Eof do 
      begin 
         if not FieldValues['IsBaddy'] then//不是坏人,则加入“我的好友” 
         begin 
            SideBar.ActiveGroupIndex:=0; 
            NewItem:=SideBar.ActiveGroup.Items.Add; 
            NewItem.Caption:=FieldValues['UserName']; 
            NewItem.LargeImage:=FieldValues['FaceID']+85; 
            NewItem.SmallImage:=FieldValues['FaceID']+85; 
            NewItem.Tag:=StrToInt(FieldValues['QQNumber']); 
         end 
         else 
         begin//是坏人,则加入“黑名单”列表 
            SideBar.ActiveGroupIndex:=2; 
            NewItem:=SideBar.ActiveGroup.Items.Add; 
            NewItem.Caption:=FieldValues['UserName']; 
            NewItem.LargeImage:=FieldValues['FaceID']+85; 
            NewItem.SmallImage:=FieldValues['FaceID']+85; 
            NewItem.Tag:=StrToInt(FieldValues['QQNumber']); 
         end; 
      Next; 
      end; 
   end; 
//将“我的好友”这个组设置为ActiveGroup 
   SideBar.Groups[0].MakeActive; 
 
//create the SETUP.INI file 
   if not FileExists(ExtractFilePath(Application.ExeName)+'setup.ini') then 
   begin 
      StrLst := TStringList.Create; 
      try 
         StrLst.Append('[INFO]'); 
         StrLst.Append('LastUser='); 
         StrLst.SaveToFile(ExtractFilePath(Application.ExeName)+'setup.ini'); 
      finally 
         StrLst.Free; 
      end; 
   end; 
//create the FNDSETUP.INI file 
   if not FileExists(ExtractFilePath(Application.ExeName)+sQQNumber+'\fndsetup.ini') then 
   begin 
      StrLst := TStringList.Create; 
      try 
         StrLst.Append('[SETUP]'); 
         StrLst.Append('AutoShowMsg=0'); 
         StrLst.Append('AskClose=1'); 
         StrLst.Append('OnlineInfo=1'); 
          
         StrLst.Append('FormLeft=50'); 
         StrLst.Append('FormTop=50'); 
 
         StrLst.Append('LeaveMsg1=这是NetMessage的自动回复信息,我不在……'); 
         StrLst.Append('LeaveMsg2=工作中,请勿打扰……'); 
         StrLst.Append('LeaveMsg3=我去吃饭了,呆会儿见~~~~~~'); 
         StrLst.Append('LeaveMsg4=我忙,呆会儿再聊……'); 
         StrLst.SaveToFile(ExtractFilePath(Application.ExeName)+sQQNumber+'\FndSetup.ini'); 
      finally 
         StrLst.Free; 
      end; 
   end; 
 
//从FNDSETUP.INI文件中读取设置并赋值给全局变量 
   MyIni := TIniFile.Create(ExtractFilePath(Application.ExeName)+sQQNumber+'\FndSetup.ini'); 
   try 
      bAutoShowMsg:=MyIni.ReadBool('setup','AutoShowMsg',False); 
      bOnlineInfo:=MyIni.ReadBool('setup','OnlineInfo',True); 
      bAskClose:=MyIni.ReadBool('setup','AskClose',False); 
 
      FrmMain_QQ.Top:=MyIni.ReadInteger('setup','FormTop',50); 
      FrmMain_QQ.Left:=MyIni.ReadInteger('setup','FormLeft',50); 
 
      //设置离线消息菜单项的 Caption 
      ItmLeave1.Caption:=MyIni.ReadString('setup','LeaveMsg1','这是NetMessage的自动回复信息,我不在……'); 
      ItmLeave2.Caption:=MyIni.ReadString('setup','LeaveMsg2','工作中,请勿打扰……'); 
      ItmLeave3.Caption:=MyIni.ReadString('setup','LeaveMsg3','我去吃饭了,呆会儿见~~~~~~'); 
      ItmLeave4.Caption:=MyIni.ReadString('setup','LeaveMsg4','我忙,呆会儿再聊……'); 
   finally 
      MyIni.Free; 
   end; 
 
 
end; 
 
procedure TFrmMain_QQ.UDPDataReceived(Sender: TComponent; 
  NumberBytes: Integer; FromIP: String; Port: Integer); 
var 
   sMsg,sPath,sBmpName:string; 
   MyStream:TMemoryStream; 
   Hnd:THandle; 
//   bIsInDB,bIsInImgLsgBox:boolean; 
   i:integer; 
   MyFace,SmallFace:TBitmap; 
begin 
//   if FromIP=g_sIP then Exit;{过滤自己的信息} 
   if  NumberBytes=-1 then Exit;//{此句可以消除write stream error的错误} 
//把收到的流信息转换为string类型,并赋值给变量sMsg 
   MyStream := TMemoryStream.Create; 
   try 
      Udp.ReadStream(MyStream); 
      SetLength(sMsg,NumberBytes); 
      MyStream.Read(sMsg[1],NumberBytes); 
   finally 
      Mystream.Free; 
   end; 
//showmessage(smsg); 
   FrmMain_QQ.ExtractMsg(sMsg);//先分解,下面为判断后处理 
//showmessage(amsg[1]);///////////////////////////////////////////////////////////// 
//判断是否为“上线”信息,并且判断用户信息,更新好友数据库 
   if aMsg[1]='ONL' then 
   begin 
      MyStream:=TmemoryStream.Create; 
      try 
         sMsg:='IMO'+'*'+sQQNumber+'*'+sUserName+'*'+IntToStr(iFaceID)+'*';//原来为2位,现在改为4位 
         MyStream.Write(sMsg[1],Length(sMsg)); 
         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]); 
                  SideBar.Groups[0].Items[i].SmallImage:=StrToInt(aMsg[4]); 
                  Break; 
               end; 
            end; 
            for i := 0 to SideBar.Groups[2].ItemCount-1 do 
            begin 
               if SideBar.Groups[2].Items[i].Tag=StrToInt(aMsg[2]) then 
               begin 
                  SideBar.Groups[2].Items[i].Caption:=aMsg[3]; 
                  SideBar.Groups[2].Items[i].LargeImage:=StrToInt(aMsg[4]); 
                  SideBar.Groups[2].Items[i].SmallImage:=StrToInt(aMsg[4]); 
                  Break; 
               end; 
            end;{结束更新BtnBar上显示的好友信息} 
         end; 
      end; 
   end; 
 
 
end; 
 
procedure TFrmMain_QQ.ItmImgLargeClick(Sender: TObject); 
var 
   i:integer; 
begin 
   for i := 0 to SideBar.GroupCount-1 do 
   begin 
      SideBar.Groups[0].IconType:= dxsgLargeIcon; 
   end; 
end; 
 
procedure TFrmMain_QQ.ItmImgSmallClick(Sender: TObject); 
var 
   i:integer; 
begin 
      for i := 0 to SideBar.GroupCount-1 do 
   begin 
      SideBar.Groups[i].IconType:= dxsgSmallIcon; 
   end; 
end; 
 
procedure TFrmMain_QQ.BtnSearchClick(Sender: TObject); 
var 
  Hnd:THandle; 
  i:integer; 
  NewItem:TdxSideBarItem; 
  bTmp:Boolean; 
begin 
  Hnd:=FindWindow('TFrmFindFriends','查找用户'); 
  if not Hnd<>0 then 
  begin 
    FrmFindFriends:=TFrmFindFriends.Create(Application); 
    try 
      FrmFindFriends.ShowModal; 
      FrmFindFriends.Update; 
    finally 
      FrmFindFriends.Release; 
    end; 
  end; 
 
//将所加的好友头像加入BtnBar 
//在数据库中查找尚未被加入BtnBar中的好友,即新添加的好友 
    bTmp:=true; 
    with DMShare.TblFriends do 
    begin 
        First; 
        while not Eof do 
        begin 
            for i := 0 to SideBar.Groups[0].ItemCount-1 do 
            begin 
                if StrToInt(FieldValues['QQNumber'])=SideBar.Groups[0].Items[i].Tag then 
                begin 
                  bTmp:=False; 
                  Break; 
                end 
                else 
                begin 
                  bTmp:=True;    
                end; 
            end; 
            if bTmp then 
            begin 
                SideBar.ActiveGroupIndex:=0; 
                NewItem:=SideBar.ActiveGroup.Items.Add; 
                NewItem.Caption:=FieldValues['UserName']; 
                NewItem.LargeImage:=FieldValues['FaceID'] ; 
                NewItem.SmallImage:=FieldValues['FaceID']; 
                NewItem.Tag:=StrToInt(FieldValues['QQNumber']); 
                NewItem.Index:=0;//将所添加的头像提到最上面 
            end; 
            Next; 
        end; 
    end; 
 
 
 
 
 
(*   for i := 0 to 255 do   {这里是0到255,也就是说同时添加的好友不参超过256个, 
                           其实这是不科学地,最好的做法是使用while aAddFndLst[i,0]<>'' do 
                           这样才是最好地,以后再改吧!!} 
   begin 
      if aAddFndLst[i,0]<>'' then 
      begin 
 
         SideBar.ActiveGroupIndex:=0; 
         NewItem:=SideBar.ActiveGroup.Items.Add; 
         NewItem.Caption:=aAddFndLst[i,1]; 
         NewItem.LargeImage:=StrToInt(aAddFndLst[i,2]); 
         NewItem.SmallImage:=StrToInt(aAddFndLst[i,2]); 
         NewItem.Tag:=StrToInt(aAddFndLst[i,0]); 
         NewItem.Index:=0;//将所添加的头像提到最上面 
      end 
      else 
      begin 
         Break; 
      end; 
   end; 
{清空存储所添加好友的数组} 
   for i := 0 to 255 do 
   begin 
      aAddFndLst[i,0]:=''; 
   end; 
*) 
end; 
 
procedure TFrmMain_QQ.BtnBarChange(Sender: TObject); 
var 
   sFileName:string; 
begin 
   sFileName:=ExtractFilePath(Application.ExeName)+'sound\folder.wav'; 
   sndPlaySound(PChar(sFileName),SND_ASYNC) 
end; 
 
procedure TFrmMain_QQ.ItmSendMsgClick(Sender: TObject); 
var 
   MyFace:TBitmap; 
   sPath,sBmp1,sBmp2:string; 
   i,j:integer; 
   bExistFrmMsg,bCreateFrmMsg:boolean; 
begin 
   bExistFrmMsg:=False; 
   bCreateFrmMsg:=True; 
{判断消息窗体是否已经创建,是则显示} 
   for i := 0 to 254 do 
   begin 
      if WndRecArr[i].QQNum=IntToStr(ActiveItem.Tag) then 
      begin 
         WndRecArr[i].PForm.Show; 
         WndRecArr[i].PForm.BtnRevert.SetFocus; 
         ActiveItem:=nil; 
         WndRecArr[i].QQNum:='';//一定要释放这个窗体所占用的数组空间 
         bCreateFrmMsg:=False;//为假,不需要创建消息窗体了 
         Break; 
//         Exit; 
      end; 
   end; 
 
   {判断是否继续托盘图标的跳动,具体说明参照procedure TFrmMain_QQ.TrayIconDblClick(Sender: TObject);} 
   if TrayIcon.CycleIcons then 
   begin 
      for j := 0 to 254 do 
      begin 
         if WndRecArr[j].QQNum<>'' then 
         begin 
            bExistFrmMsg:=True; 
            Break; 
         end; 
      end; 
   if not bexistFrmMsg then 
      begin 
         TrayIcon.CycleIcons:=False; 
//               TrayIcon.IconList:=nil; 
         DMShare.IconList.GetIcon(1,TrayIcon.Icon); 
      end; 
   end; 
 
 
 
{没有创建消息窗体则创建一个发送消息窗体} 
if bCreateFrmMsg then 
begin 
   with TFrmMsg.Create(Application) do 
   begin 
//      Height:=290; 
      Caption:='发送消息'; 
      LabSendTo.Caption:='发送给:'; 
      BtnSend.Enabled:=False; 
      BtnRevert.Enabled:=False; 
      LabQQNumber.Visible:=False; 
      LabQQNumber.Caption:=IntToStr(ActiveItem.Tag); 
 
      DMShare.TblFriends.First;//显示好友妮称 
      if DMShare.TblFriends.Locate('QQNumber',IntToStr(ActiveItem.Tag),[]) then 
      begin 
         PnlUserName.Caption:=DMShare.TblFriends.FieldValues['UserName']; 
      end; 
//显示好友头像 
      {先将头像提取出存储在硬盘上} 
      MyFace:=TBitMap.Create; 
      sPath:=ExtractFilePath(Application.ExeName)+'temp\'; 
      sBmp1:=IntToStr(ActiveItem.Tag)+'_1.bmp'; 
      sBmp2:=IntToStr(ActiveItem.Tag)+'_2.bmp'; 
      if not FileExists(sPath+sBmp1) then 
      begin 
         DMShare.ImgLarge.GetBitmap(ActiveItem.LargeImage,MyFace); 
         MyFace.SaveToFile(sPath+sBmp1);{存储第一张图} 
      end; 
      if not FileExists(sPath+sBmp2) then 
      begin 
         DMShare.ImgLarge.GetBitmap(ActiveItem.LargeImage+170,MyFace); 
         MyFace.SaveToFile(sPath+sBmp2);{存储第二张图} 
      end; 
 
      DMShare.ImgLarge.GetBitmap(ActiveItem.LargeImage,ImgFace.Picture.Bitmap); 
//      ImgFace.Picture.Bitmap:=MyFace; 
 
      if (FileExists(sPath+sBmp1)) and 
         (FileExists(sPath+sBmp2))  then 
      begin 
         Timer.Enabled:=True;  {用定时器使好友眨眼睛} 
      end; 
 
      ActiveItem:=nil;//消除全局变量的值,此值的生效时间不能长 
 
      Show; 
      Update; 
   end; 
end; 
 
end; 
 
procedure TFrmMain_QQ.FormClose(Sender: TObject; var Action: TCloseAction); 
var 
   MyIni:TIniFile; 
begin 
   DMShare.TblFriends.Close; 
   DMShare.TblChatLog.Close; 
   DMShare.TblSystemMsg.Close; 
   FrmMain_QQ.Offline; 
//存储窗体位置 
   MyIni:=TIniFile.Create(ExtractFilePath(Application.ExeName)+sQQNumber+'\FndSetup.ini'); 
   try 
      MyIni.WriteInteger('SETUP','FormLeft',FrmMain_QQ.Left); 
      MyIni.WriteInteger('SETUP','FormTop',FrmMain_QQ.Top); 
   finally 
      MyIni.Free; 
   end; 
 
    //删除临时目录 
   if DirectoryExists(ExtractFilePath(Application.ExeName)+'temp') then 
   begin 
      Deltree(ExtractFilePath(Application.ExeName)+'temp'); 
   end; 
 
end; 
 
procedure TFrmMain_QQ.SideBarItemClick(Sender: TObject; Item: TdxSideBarItem); 
var 
   CursorPos:TPoint; 
begin 
//判断“发送信息”命令是否可用 
   if Item.LargeImage>84 then 
   begin 
      ItmSendMsg.Enabled:=False; 
   end 
   else 
   begin 
      ItmSendMsg.Enabled:=True; 
   end; 
 
//判断“大图标”,“小图标”命令谁可用 
   if SideBar.Groups[0].IconType=dxsgLargeIcon then 
   begin 
      ItmImgSmall.Enabled:=True; 
      ItmImgLarge.Enabled:=False; 
   end 
   else 
   begin 
      ItmImgSmall.Enabled:=False; 
      ItmImgLarge.Enabled:=True; 
   end; 
 
//判断“加入黑名单”是否可用 
   if SideBar.ActiveGroupIndex=2 then 
      ItmBeBaddy.Caption:='加为好友(&A)' 
   else 
      ItmBeBaddy.Caption:='加入黑名单(&A)'; 
 
   GetCursorPos(CursorPos); 
   PMItem.Popup(CursorPos.X,CursorPos.Y); 
 
//将当前Item赋给全局变量ActiveItem,以便在创建发送消息窗体时使用 
   ActiveItem:=Item; 
end; 
 
procedure TFrmMain_QQ.SideBarDblClick(Sender: TObject); 
begin 
   if SideBar.FocusedItem<>nil then 
   begin 
      ItmSendMsg.Click; 
   end; 
end; 
 
procedure TFrmMain_QQ.SideBarMouseDown(Sender: TObject; Button: TMouseButton; 
  Shift: TShiftState; X, Y: Integer); 
var 
   CursorPos:TPoint; 
begin 
   if (SideBar.FocusedItem<>nil) and 
      (Button=mbRight) and 
      (SideBar.FocusedItem.LargeImage<85) then 
   begin 
      //将当前Item赋给全局变量ActiveItem,以便在创建发送消息窗体时使用 
      ActiveItem:=SideBar.FocusedItem; 
      ItmSendMsg.Click; 
   end; 
 
   if (SideBar.FocusedItem=nil) and 
      (Button=mbRight) then 
   begin 
      //判断“删除组”、“改名组”是否可用? 
      if (SideBar.ActiveGroupIndex=0) or 
         (SideBar.ActiveGroupIndex=1) or 
         (SideBar.ActiveGroupIndex=2) then 
      begin 
         ItmRenameGroup.Enabled:=False; 
         ItmDelGroup.Enabled:=False; 
      end 
      else 
      begin 
         ItmRenameGroup.Enabled:=True; 
         ItmDelGroup.Enabled:=True; 
      end; 
 
       
      GetCursorPos(CursorPos); 
      PMGroup.Popup(CursorPos.X,CursorPos.Y); 
   end; 
end; 
 
procedure TFrmMain_QQ.ItmSetupClick(Sender: TObject); 
begin 
   with TFrmSetup.Create(Application) do 
   begin 
      try 
        PageControl1.ActivePage:=TabSystem; 
        ShowModal; 
        Update; 
      finally 
        Release; 
      end; 
   end; 
end; 
 
procedure TFrmMain_QQ.ItmSelfSetupClick(Sender: TObject); 
begin 
   with TFrmSetup.Create(Application) do 
   begin 
      try 
        PageControl1.ActivePage:=TabSelf; 
        ShowModal; 
        Update; 
      finally 
        Release; 
      end; 
   end; 
end; 
 
procedure TFrmMain_QQ.ItmSelfSetup2Click(Sender: TObject); 
begin 
   ItmSelfSetup.Click; 
end; 
 
procedure TFrmMain_QQ.ItmSysSetupClick(Sender: TObject); 
begin 
   ItmSetup.Click; 
end; 
 
procedure TFrmMain_QQ.ItmDelFriendClick(Sender: TObject); 
begin 
   if MessageBox(GetActiveWindow(),'您确认要删除此好友吗?', 
                  '删除好友',MB_YESNO+MB_ICONQUESTION)=IDYES then 
   begin 
      with DMShare.TblFriends do 
      begin 
         First; 
         if Locate('QQNumber',IntToStr(ActiveItem.Tag),[]) then 
         begin 
            Delete; 
         end; 
      end; 
      ActiveItem.Free; 
      ActiveItem:=nil; 
   End; 
end; 
 
procedure TFrmMain_QQ.ItmBeBaddyClick(Sender: TObject); 
Var 
   NewItem:TdxSideBarItem; 
begin 
   if ItmBeBaddy.Caption='加入黑名单(&A)' then 
   begin 
      if MessageBox(GetActiveWindow(),'您确定要将其加入黑名单吗?', 
                     '加入黑名单',MB_YESNO+MB_ICONQUESTION)=IDYES then 
      begin 
         with DMShare.TblFriends do 
         begin 
            First; 
            if Locate('QQNumber',IntToStr(ActiveItem.Tag),[]) then 
            begin 
               Edit; 
               FieldValues['IsBaddy']:=True; 
               Post; 
            end; 
         end; 
 
         NewItem:=SideBar.Groups[2].Items.Add; 
         NewItem.Tag:=ActiveItem.Tag; 
         NewItem.Caption:=ActiveItem.Caption; 
         NewItem.LargeImage:=ActiveItem.LargeImage; 
         NewItem.SmallImage:=ActiveItem.SmallImage; 
         NewItem.Index:=0; 
 
         ActiveItem.Free; 
         ActiveItem:=nil; 
      end; 
   end 
   else 
   begin 
      if MessageBox(GetActiveWindow(),'您确定要将其加为好友吗?', 
                     '加为好友',MB_YESNO+MB_ICONQUESTION)=IDYES then 
      begin 
         with DMShare.TblFriends do 
         begin 
            First; 
            if Locate('QQNumber',IntToStr(ActiveItem.Tag),[]) then 
            begin 
               Edit; 
               FieldValues['IsBaddy']:=False; 
               Post; 
            end; 
         end; 
 
         NewItem:=SideBar.Groups[0].Items.Add; 
         NewItem.Tag:=ActiveItem.Tag; 
         NewItem.Caption:=ActiveItem.Caption; 
         NewItem.LargeImage:=ActiveItem.LargeImage; 
         NewItem.SmallImage:=ActiveItem.SmallImage; 
         NewItem.Index:=0; 
 
         ActiveItem.Free; 
         ActiveItem:=nil; 
      end; 
   end; 
end; 
 
procedure TFrmMain_QQ.ItmRenameGroupClick(Sender: TObject); 
begin 
   SideBar.EditGroup(SideBar.ActiveGroup); 
end; 
 
procedure TFrmMain_QQ.ItmAddGroupClick(Sender: TObject); 
var 
   NewGroup:TdxSideGroup; 
begin 
   NewGroup:=SideBar.Groups.Add; 
   NewGroup.Index:=SideBar.GroupCount-1; 
   SideBar.EditGroup(NewGroup); 
end; 
 
procedure TFrmMain_QQ.ItmDelGroupClick(Sender: TObject); 
begin 
   if MessageBox(GetActiveWindow,'您确认要将此组删除?', 
                  '删除组',MB_YESNO+MB_ICONQUESTION)=IDYES then 
   begin 
      SideBar.ActiveGroup.Free; 
   end; 
end; 
 
procedure TFrmMain_QQ.TimHideFormTimer(Sender: TObject); 
var 
   CursorPos:TPoint; 
begin 
   GetCursorPos(CursorPos); 
   {hide the form FrmMain} 
   if (not bHide) and 
      (FrmMain_QQ.Top<=5) and 
      ( 
         (CursorPos.X(FrmMain_QQ.Left+frmMain_QQ.Width)) or 
         (CursorPos.Y(FrmMain_QQ.Top+FrmMain_QQ.Height)) 
      ) then 
   begin 
      FrmMain_QQ.Top:=-(FrmMain_QQ.Height-3); 
      bHide:=True; 
   end; 
 
   {Show the form FrmMain} 
   if bHide and 
      (CursorPos.X>FrmMain_QQ.Left) and 
      (CursorPos.X<(FrmMain_QQ.Left+FrmMain_QQ.Width)) and 
      (CursorPos.Y<=5) then 
   begin 
      FrmMain_QQ.Top:=0; 
      bHide:=False; 
   end; 
 
end; 
 
procedure TFrmMain_QQ.HotKeySpy1HotKeys0HotKey(Sender: TObject); 
var 
   MyMouse:TMouse; 
   MousePos:TPoint; 
begin 
if TrayIcon.CycleIcons then 
begin 
   FrmMain_QQ.TrayIconDblClick(Sender); 
end 
else 
begin 
 
 
   if bHide then 
   begin 
      Application.Restore; 
      Application.BringToFront; 
      FrmMain_QQ.Top:=0; 
      bHide:=False; {此句一定要加,否则真假关系就搞乱了,窗体不会隐藏了} 
      {定位鼠标位置} 
      MyMouse:=TMouse.Create; 
      MousePos.X:=FrmMain_QQ.Left+30; 
      MousePos.Y:=20; 
      MyMouse.CursorPos:=MousePos; 
   end 
   else 
   begin 
      Application.Restore; 
      Application.BringToFront; 
   end; 
 
end; 
 
end; 
 
procedure TFrmMain_QQ.ItmOfflineClick(Sender: TObject); 
begin 
   FrmMain_QQ.Offline; 
   bLeave:=False;    
end; 
 
procedure TFrmMain_QQ.ItmHideClick(Sender: TObject); 
begin 
   FrmMain_QQ.Offline; 
   bLeave:=False;    
end; 
 
procedure TFrmMain_QQ.ItmOnlineClick(Sender: TObject); 
begin 
   FrmMain_QQ.SendOnlineMessage; 
   bLeave:=False; 
end; 
 
procedure TFrmMain_QQ.ItmLoginAgainClick(Sender: TObject); 
begin 
{  with TFrmLogin.Create(Application) do 
  begin 
    try 
      ShowModal; 
      Update; 
    finally 
      Release; 
    end; 
  end; 
} 
end; 
 
procedure TFrmMain_QQ.ItmShowMainFormClick(Sender: TObject); 
begin 
   FrmMain_QQ.HotKeySpy1HotKeys0HotKey(Sender); 
end; 
 
procedure TFrmMain_QQ.TrayIconDblClick(Sender: TObject); 
var 
  i:integer; 
  bExistFrmMsg:boolean; 
begin 
  bExistFrmMsg:=False; 
 
  if TrayIcon.CycleIcons then 
  begin 
  {显示消息窗体} 
    for i := 0 to 254 do 
    begin 
      if WndRecArr[i].QQNum<>'' then 
      begin 
        WndRecArr[i].PForm.Show; 
        WndRecArr[i].PForm.BtnRevert.SetFocus; 
        WndRecArr[i].QQNum:='';{这句不能忘啊,释放此窗体占用的数组空间} 
        Break; 
      end; 
    end; 
    {判断是否存在隐藏的消息窗体,有则继续托盘图标的跳动,无则停止跳动} 
    for i := 0 to 254 do 
    begin 
      if WndRecArr[i].QQNum<>'' then 
      begin 
        bExistFrmMsg:=True; 
        Break; 
      end; 
    end; 
    {没有隐藏的消息窗体,则停止跳动} 
    if not bExistFrmMsg then 
    begin 
      TrayIcon.CycleIcons:=False; 
      TrayIcon.IconList:=nil; 
      DMShare.IconList.GetIcon(1,TrayIcon.Icon); 
    end; 
  end; 
end; 
 
procedure TFrmMain_QQ.TrayIconClick(Sender: TObject); 
var 
   CursorPos:TPoint; 
begin 
   GetCursorPos(CursorPos); 
   PMOnline.Popup(CursorPos.X,CursorPos.Y); 
end; 
 
//自定义的事件,用于收到消息时SideBar上头像的跳动 
procedure TFrmMain_QQ.MyTimer(Sender:TObject); 
var 
   i,j,ImgIdx:integer; 
   MyItem:TdxSideBarItem; 
   MyTag:integer; 
begin 
   with Sender as TTimer do 
   begin 
      MyTag:=Tag; 
   end; 
 
   for i := 0 to SideBar.GroupCount-1 do 
   begin 
      for j := 0 to SideBar.Groups[i].ItemCount-1 do 
      begin 
         if SideBar.Groups[i].Items[j].Tag=MyTag then 
         begin 
            MyItem:=SideBar.Groups[i].Items[j]; 
//            ImgIdx:=MyItem.LargeImage; 
            Break; 
         end; 
      end; 
   end; 
//showMessage(IntToStr(imgidx)); 
 
   if MyItem<>nil then 
   begin 
      if MyItem.LargeImage<>-1 then 
      begin 
         MyItem.LargeImage:=-1; 
         MyItem.SmallImage:=-1; 
 
      end 
      else 
      begin 
{下面5行实在是不可为而为之啊,这样太……太……不好了,不断地读取数据库 
上面的语句中为 iFlag 不知为何?不能起作用啊} 
         with DMShare.TblFriends do 
         begin 
            First; 
            Locate('QQNumber',IntToStr(MyItem.Tag),[]); 
            ImgIdx:=FieldValues['FaceID']; 
         end; 
 
         MyItem.LargeImage:=ImgIdx; 
         MyItem.SmallImage:=ImgIdx; 
      end; 
   end; 
 
end; 
 
 
procedure TFrmMain_QQ.BtnHomepageClick(Sender: TObject); 
begin 
   MessageBox(GetActiveWindow(), 
               '哈哈!我的网站还没有建呢……', 
               '作者网站', 
               MB_OK+MB_ICONINFORMATION); 
end; 
 
procedure TFrmMain_QQ.FormCloseQuery(Sender: TObject; 
  var CanClose: Boolean); 
begin 
   //退出时确认 
   if bAskClose then 
   begin 
      if MessageBox(GetActiveWindow(),'您确认要退出吗?','退出',MB_YESNO+MB_ICONQUESTION)=IDNO then 
      begin 
         CanClose:=False; 
      end; 
   end; 
 
end; 
 
procedure TFrmMain_QQ.N11Click(Sender: TObject); 
begin 
   FrmAbout := TFrmAbout.Create(Application); 
   try 
      FrmAbout.ShowModal; 
   finally 
      FrmAbout.Release; 
   end; 
 
end; 
 
procedure TFrmMain_QQ.ItmLeave1Click(Sender: TObject); 
begin 
   bLeave:=True; 
   sLeaveMsg:=ItmLeave1.Caption; 
 
   ItmLeave1.Checked:=True; 
   ItmLeave2.Checked:=False; 
   ItmLeave3.Checked:=False; 
   ItmLeave4.Checked:=False; 
end; 
 
procedure TFrmMain_QQ.ItmLeave2Click(Sender: TObject); 
begin 
   bLeave:=True; 
   sLeaveMsg:=ItmLeave2.Caption; 
 
   ItmLeave1.Checked:=False; 
   ItmLeave2.Checked:=True; 
   ItmLeave3.Checked:=False; 
   ItmLeave4.Checked:=False; 
end; 
 
procedure TFrmMain_QQ.ItmLeave3Click(Sender: TObject); 
begin 
   bLeave:=True; 
   sLeaveMsg:=ItmLeave3.Caption; 
 
   ItmLeave1.Checked:=False; 
   ItmLeave2.Checked:=False; 
   ItmLeave3.Checked:=True; 
   ItmLeave4.Checked:=False; 
end; 
 
procedure TFrmMain_QQ.ItmLeave4Click(Sender: TObject); 
begin 
   bLeave:=True; 
   sLeaveMsg:=ItmLeave4.Caption; 
 
   ItmLeave1.Checked:=False; 
   ItmLeave2.Checked:=False; 
   ItmLeave3.Checked:=False; 
   ItmLeave4.Checked:=True; 
end; 
 
procedure TFrmMain_QQ.ItmByMeClick(Sender: TObject); 
begin 
   with TFrmSetup.Create(Application) do 
   begin 
      try 
        PageControl1.ActivePage:=TabMsg; 
        ShowModal; 
        Update; 
      finally 
        Release; 
      end; 
   end; 
 
end; 
 
procedure TFrmMain_QQ.N10Click(Sender: TObject); 
begin 
  MessageBox(GetActiveWindow(), 
             '嘻嘻!'+#13+ 
             '这东东太简单了,'+#13+ 
             '我想应该不用写帮助了吧?'+#13+#13+ 
             '唯一要讲地就是默认的热键:ALT+X', 
             '帮助……', 
             MB_OK+MB_IconInformation); 
end; 
 
end.