RealMessengerImpl.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:121k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit RealMessengerImpl;
  2. {$WARN SYMBOL_PLATFORM OFF}
  3. interface
  4. uses
  5.   Windows, ShellAPI, SysUtils, StrUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   ActiveX, AxCtrls, StdVcl, ExtCtrls, StdCtrls, Contnrs,
  7.   ComCtrls, ToolWin, ImgList, UrlMon, MSHtml, MMSystem, Menus, Registry,
  8.   Global, CoolTrayIcon, AppEvnts, Messages, MMPCMSup,
  9.   WinSock, vfw, Color, ShlObj, WNDES, SyncObjs, ChatingFrm,
  10.   RealMessengerUnit, MyInputBoxFrm, SelFaceFrm, MsgFrm, HistoryFrm,
  11.   SystemSetFrm, Tabs, DSUtil, DirectShow9, VideoConsts,
  12.   IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  13.   IdMessageClient, IdPOP3, Pop3ServerFrm, MMObj, MMDevice, MD5,
  14.   MMMixer, MySocket, IdUDPBase, IdUDPClient,
  15.   IdIOHandler, IdIOHandlerSocket, IdSocks, Gauges, IdAntiFreezeBase,
  16.   IdAntiFreeze, IdHTTP, bsSkinMenus, bsSkinData, BusinessSkinForm,
  17.   OleCtrls, SHDocVw, Mask, bsSkinBoxCtrls, bsSkinCtrls, bsSkinTabs, RxGIF;
  18. type
  19.   TViewStyle = (vsTree, vsOnlineOffline, vsGroup);
  20.   TRealMessengerX = class(TForm)
  21.     ImgToolbarLeft: TImage;
  22.     ImgTitle: TImage;
  23.     ImgDraw: TImage;
  24.     ImgTitleLeft: TImage;
  25.     ImgTitleRight: TImage;
  26.     ImgToolbarRight: TImage;
  27.     ImgToolbar: TImage;
  28.     ImgBorderLeft: TImage;
  29.     ImgBottomLeft: TImage;
  30.     ImgBottom: TImage;
  31.     ImgBottomRight: TImage;
  32.     ImgBorderRight: TImage;
  33.     ImgClosed: TImage;
  34.     ImgMin: TImage;
  35.     bsSkinPanel1: TbsSkinPanel;
  36.     ImgEmail: TImage;
  37.     LblMyState: TLabel;
  38.     ImgMyState: TImage;
  39.     LblMailCount: TLabel;
  40.     bsSkinMenuSpeedButton1: TbsSkinMenuSpeedButton;
  41.     LblFile: TLabel;
  42.     bsSkinMenuSpeedButton2: TbsSkinMenuSpeedButton;
  43.     PnlRoot: TPanel;
  44.     Image1: TImage;
  45.     bsSkinPageControl1: TbsSkinPageControl;
  46.     bsSkinTabSheet1: TbsSkinTabSheet;
  47.     PnlWorkSpace: TPanel;
  48.     PBLogin: TPanel;
  49.     Gauge: TGauge;
  50.     LblLoging: TLabel;
  51.     LblCancelLogin: TLabel;
  52.     bsSkinScrollBar1: TbsSkinScrollBar;
  53.     bsSkinScrollBar2: TbsSkinScrollBar;
  54.     TrevUserList: TbsSkinTreeView;
  55.     bsSkinPanel3: TbsSkinPanel;
  56.     Image2: TImage;
  57.     edturl: TbsSkinEdit;
  58.     bsSkinPanel4: TbsSkinPanel;
  59.     bsSkinButton2: TbsSkinButton;
  60.     bsSkinPanel5: TbsSkinPanel;
  61.     bsSkinTabSheet2: TbsSkinTabSheet;
  62.     bsSkinPanel2: TbsSkinPanel;
  63.     WBSMS: TWebBrowser;
  64.     bsSkinTabSheet3: TbsSkinTabSheet;
  65.     WBHY: TWebBrowser;
  66.     HartTimer: TTimer;
  67.     PpMenuRight: TPopupMenu;
  68.     NR1: TMenuItem;
  69.     NR2: TMenuItem;
  70.     NR3: TMenuItem;
  71.     NR4: TMenuItem;
  72.     N5: TMenuItem;
  73.     sdfa1: TMenuItem;
  74.     NR5: TMenuItem;
  75.     NSplitOfGroup: TMenuItem;
  76.     NNewGroup: TMenuItem;
  77.     NDelGroup: TMenuItem;
  78.     NAddGroupMember: TMenuItem;
  79.     NRemoveFromGroup: TMenuItem;
  80.     CoolTrayIcon: TCoolTrayIcon;
  81.     ImgLstTrayIcon: TImageList;
  82.     ImgLstMsgAlert: TImageList;
  83.     STimer: TTimer;
  84.     PpMenuStates: TPopupMenu;
  85.     NS1: TMenuItem;
  86.     NS2: TMenuItem;
  87.     NS3: TMenuItem;
  88.     NS4: TMenuItem;
  89.     NS5: TMenuItem;
  90.     NS6: TMenuItem;
  91.     NS7: TMenuItem;
  92.     NS8: TMenuItem;
  93.     N15: TMenuItem;
  94.     NS9: TMenuItem;
  95.     TimerAutoConnect: TTimer;
  96.     TimerTopBar: TTimer;
  97.     PopupMenuShortCut: TPopupMenu;
  98.     N8: TMenuItem;
  99.     ClientPOP3: TIdPOP3;
  100.     Device: TMMMixerDevice;
  101.     TimeCheckTransmitFileError: TTimer;
  102.     ClientTCP: TIdTCPClient;
  103.     IdIOHandlerSocket1: TIdIOHandlerSocket;
  104.     IdSocksInfo1: TIdSocksInfo;
  105.     MsgTimer: TTimer;
  106.     KeepP2PSessionTimer: TTimer;
  107.     ApplicationEvents1: TApplicationEvents;
  108.     TimerLoging: TTimer;
  109.     TimeCheckAVError: TTimer;
  110.     IdAntiFreeze1: TIdAntiFreeze;
  111.     bsBusinessSkinForm1: TbsBusinessSkinForm;
  112.     bsSkinData1: TbsSkinData;
  113.     Skin1: TbsCompressedStoredSkin;
  114.     Timer1: TTimer;
  115.     PopHelp: TbsSkinPopupMenu;
  116.     N14: TMenuItem;
  117.     N16: TMenuItem;
  118.     Timer2: TTimer;
  119.     IdHTTP1: TIdHTTP;
  120.     ImglstTreeIcons: TImageList;
  121.     PopFile: TPopupMenu;
  122.     MOpen: TMenuItem;
  123.     MConnect: TMenuItem;
  124.     MConnectSet: TMenuItem;
  125.     MDisconnect: TMenuItem;
  126.     C1: TMenuItem;
  127.     MChangeNameAndPassword: TMenuItem;
  128.     N3: TMenuItem;
  129.     MMyState: TMenuItem;
  130.     MOnline: TMenuItem;
  131.     MBusy: TMenuItem;
  132.     MWillBack: TMenuItem;
  133.     MLeave: TMenuItem;
  134.     MPhone: TMenuItem;
  135.     MRepast: TMenuItem;
  136.     NMeeting: TMenuItem;
  137.     MOther: TMenuItem;
  138.     N9: TMenuItem;
  139.     MOffline: TMenuItem;
  140.     N2: TMenuItem;
  141.     MAutoLeave: TMenuItem;
  142.     MAutoBusy: TMenuItem;
  143.     N6: TMenuItem;
  144.     MSendMsg: TMenuItem;
  145.     MSendFile: TMenuItem;
  146.     MSendVoice: TMenuItem;
  147.     MSendVideo: TMenuItem;
  148.     N11: TMenuItem;
  149.     MAVSets: TMenuItem;
  150.     N7: TMenuItem;
  151.     MShowHistory: TMenuItem;
  152.     N4: TMenuItem;
  153.     MExit: TMenuItem;
  154.     Label1: TLabel;
  155.     procedure TrevUserListGetImageIndex(Sender: TObject; Node: TTreeNode);
  156.     procedure TrevUserListCustomDrawItem(Sender: TCustomTreeView;
  157.       Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
  158.     procedure MConnectClick(Sender: TObject);
  159.     procedure MTreeClick(Sender: TObject);
  160.     procedure MOnOrOffClick(Sender: TObject);
  161.     procedure MOfflineClick(Sender: TObject);
  162.     procedure MOtherClick(Sender: TObject);
  163.     procedure TrevUserListDblClick(Sender: TObject);
  164.     procedure ClientLogin();
  165.     procedure ClientLogout();
  166.     procedure ActiveFormCreate(Sender: TObject);
  167.     procedure MDisconnectClick(Sender: TObject);
  168.     procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
  169.     procedure LblMyStateClick(Sender: TObject);
  170.     procedure HartTimerTimer(Sender: TObject);
  171.     procedure TrevUserListMouseDown(Sender: TObject; Button: TMouseButton;
  172.       Shift: TShiftState; X, Y: Integer);
  173.     procedure TrevUserListChange(Sender: TObject; Node: TTreeNode);
  174.     procedure MAutoLeaveClick(Sender: TObject);
  175.     procedure MAutoBusyClick(Sender: TObject);
  176.     procedure NR2Click(Sender: TObject);
  177.     procedure NR3Click(Sender: TObject);
  178.     procedure NR4Click(Sender: TObject);
  179.     procedure CoolTrayIconDblClick(Sender: TObject);
  180.     procedure NR5Click(Sender: TObject);
  181.     procedure TrevUserListMouseMove(Sender: TObject; Shift: TShiftState; X,
  182.       Y: Integer);
  183.     procedure STimerTimer(Sender: TObject);
  184.     procedure ActiveFormDestroy(Sender: TObject);
  185.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  186.     procedure MExitClick(Sender: TObject);
  187.     procedure FormShow(Sender: TObject);
  188.     procedure TimerAutoConnectTimer(Sender: TObject);
  189.     procedure MGroupClick(Sender: TObject);
  190.     procedure NNewGroupClick(Sender: TObject);
  191.     procedure NDelGroupClick(Sender: TObject);
  192.     procedure NRemoveFromGroupClick(Sender: TObject);
  193.     procedure NAddGroupMemberClick(Sender: TObject);
  194.     procedure MConnectSetClick(Sender: TObject);
  195.     procedure MShowSysHistoryClick(Sender: TObject);
  196.     procedure LblFileClick(Sender: TObject);
  197.     procedure ImgClosedClick(Sender: TObject);
  198.     procedure ImgMinMouseDown(Sender: TObject; Button: TMouseButton;
  199.       Shift: TShiftState; X, Y: Integer);
  200.     procedure ImgMinMouseUp(Sender: TObject; Button: TMouseButton;
  201.       Shift: TShiftState; X, Y: Integer);
  202.     procedure LblFileMouseMove(Sender: TObject; Shift: TShiftState; X,
  203.       Y: Integer);
  204.     procedure TimerTopBarTimer(Sender: TObject);
  205.     procedure LblFileMouseDown(Sender: TObject; Button: TMouseButton;
  206.       Shift: TShiftState; X, Y: Integer);
  207.     procedure ImgMinClick(Sender: TObject);
  208.     procedure ImgTitleMouseDown(Sender: TObject; Button: TMouseButton;
  209.       Shift: TShiftState; X, Y: Integer);
  210.     procedure LblMailCountClick(Sender: TObject);
  211.     procedure MAVSetsClick(Sender: TObject);
  212.     procedure ClientTCPDisconnected(Sender: TObject);
  213.     procedure ClientTCPConnected(Sender: TObject);
  214.     procedure TimeCheckTransmitFileErrorTimer(Sender: TObject);
  215.     procedure FormResize(Sender: TObject);
  216.     procedure MsgTimerTimer(Sender: TObject);
  217.     procedure KeepP2PSessionTimerTimer(Sender: TObject);
  218.     procedure TimerLogingTimer(Sender: TObject);
  219.     procedure TimeCheckAVErrorTimer(Sender: TObject);
  220.     procedure MChangeNameAndPasswordClick(Sender: TObject);
  221.     procedure bsSkinMenuSpeedButton2Click(Sender: TObject);
  222.     procedure N14Click(Sender: TObject);
  223.     procedure N17Click(Sender: TObject);
  224.     procedure N16Click(Sender: TObject);
  225.   private
  226.     ImgIndex, LastImgIndex: Integer;
  227.   protected
  228.     { Protected declarations }
  229.   public
  230.     IsInIE: Boolean;
  231.     HotKeyMgrIsProcessing: Boolean;
  232.     CurNode: TTreeNode;
  233.     procedure SendIdentity;
  234.     procedure GetInit();
  235.     procedure UpdateListViewStates(TV: TbsSkinTreeView; Node: TTreeNode);
  236.     procedure UpdateMyState();
  237.     procedure ChangeMyState(State: string; IsAutoState: Boolean = False);
  238.     procedure ChangeLblMyStateCaption();
  239.     procedure FlashTray(ChatingForm: TChatingForm);
  240.     procedure Login();
  241.     procedure GetListViewData(TV: TbsSkinTreeView; ViewStyle: TViewStyle = vsTree; IsForSelForm: Boolean = False); //显示用户列表
  242.     procedure TestVideoDevice();
  243.     procedure TestAudioDevice();
  244.     procedure ShowImage(PHandle: HWND; BitMap: HBitMap; Buf: PByte);
  245.     procedure WMDEVICECHANGE(var msgx: Tmessage); message WM_DEVICECHANGE;
  246.     procedure WMMOVE(var Msg: Tmessage); message WM_MOVE;
  247.     procedure ProcessCBInputing(CBInputing: TCBInputing);
  248.     procedure ProcessCBReturnMessage(CBReturnMessage: TCBReturnMessage);
  249.     procedure ProcessCBMessage(CBMessage: TCBMessage);
  250.     procedure ProcessCBSendFileResult(CBSendFileResult: TCBSendFileResult);
  251.     procedure ProcessCBSendFilePackage(CBSendFilePackage: TCBSendFilePackage);
  252.     procedure ProcessCBAudio(CBAudio: TCBAudio);
  253.     procedure ProcessCBVideo(CBVideo: TCBVideo);
  254.   end;
  255.   TClientHandleThread = class(TThread)
  256.   private
  257.     FLock: TCriticalSection;
  258.     CBLoginResult: TCBLoginResult;
  259.     CBSendBranch: TCBSendBranch;
  260.     CBSendEmployee: TCBSendEmployee;
  261.     CBStateChanged: TCBStateChanged;
  262.     CBInputing: TCBInputing;
  263.     CBMessage: TCBMessage;
  264.     CBReturnMessage: TCBReturnMessage;
  265.     CBAddUser: TCBAddUser;
  266.     CBSendFileRequest: TCBSendFileRequest;
  267.     CBSendFileCancle: TCBSendFileCancle;
  268.     CBSendFileStop: TCBSendFileStop;
  269.     CBSendFileResponse: TCBSendFileResponse;
  270.     CBSendFileResult: TCBSendFileResult;
  271.     CBSendFilePackage: TCBSendFilePackage;
  272.     CBSendFileResume: TCBSendFileResume;
  273.     CBSendFileCompleted: TCBSendFileCompleted;
  274.     CBAudioRequest: TCBAudioRequest;
  275.     CBAudioResponse: TCBAudioResponse;
  276.     CBAudioCancel: TCBAudioCancel;
  277.     CBAudio: TCBAudio;
  278.     CBAudioStop: TCBAudioStop;
  279.     CBVideoRequest: TCBVideoRequest;
  280.     CBVideoResponse: TCBVideoResponse;
  281.     CBVideoCancel: TCBVideoCancel;
  282.     CBVideoStop: TCBVideoStop;
  283.     CBSetBitmapInfo: TCBSetBitmapInfo;
  284.     CBSetCompvars: TCBSetCompvars;
  285.     CBVideo: TCBVideo;
  286.     CBBeginTalk: TCBBeginTalk;
  287.     CBPleaseUseTCP: TCBPleaseUseTCP;
  288.     CBNameAndPasswordChanged: TCBNameAndPasswordChanged;
  289.     procedure ProcessCBSendBranch;
  290.     procedure ProcessCBSendEmployee;
  291.     procedure ProcessCBLoginResult;
  292.     procedure ProcessCBStateChanged;
  293.     procedure ProcessCBInputing;
  294.     procedure ProcessCBMessage;
  295.     procedure ProcessCBReturnMessage;
  296.     procedure ProcessCBAddUser;
  297.     procedure ProcessCBSendFileRequest;
  298.     procedure ProcessCBSendFileCancle;
  299.     procedure ProcessCBSendFileStop;
  300.     procedure ProcessCBSendFileResponse;
  301.     procedure ProcessCBSendFileResult;
  302.     procedure ProcessCBSendFilePackage;
  303.     procedure ProcessCBSendFileResume;
  304.     procedure ProcessCBSendFileCompleted;
  305.     procedure ProcessCBAudioRequest;
  306.     procedure ProcessCBAudioResponse;
  307.     procedure ProcessCBAudioCancel;
  308.     procedure ProcessCBAudio;
  309.     procedure ProcessCBAudioStop;
  310.     procedure ProcessCBVideoRequest;
  311.     procedure ProcessCBVideoResponse;
  312.     procedure ProcessCBVideoCancel;
  313.     procedure ProcessCBVideoStop;
  314.     procedure ProcessCBSetBitmapInfo;
  315.     procedure ProcessCBSetCompvars;
  316.     procedure ProcessCBVideo;
  317.     procedure ProcessCBBeginTalk;
  318.     procedure ProcessCBPleaseUseTCP;
  319.     procedure ProcessCBNameAndPasswordChanged;
  320.   public
  321.     constructor Create;
  322.     destructor Destroy; override;
  323.     procedure Execute; override;
  324.   end;
  325. var
  326.   ConnectedTicket: Cardinal;
  327.   RealMessengerX: TRealMessengerX;
  328.   CheckPOP3ThreadHandle: THandle;
  329.   ClientHandleThread: TClientHandleThread;
  330.   LastMailCount, CurrentMailCount: Integer;
  331. implementation
  332. uses ComObj, ComServ, LoginFrm, SelUserFrm, AboutFrm, TempFrm, VideoFrm,
  333.   CopyScreenFrm, AVSetFrm, ChangeNameAndPasswordFrm;
  334. {$R *.DFM}
  335. function GetFormNameAt(X, Y: Integer): string;
  336. var
  337.   P: TPoint;
  338.   W: TWinControl;
  339. begin
  340.   P.X := X;
  341.   P.Y := Y;
  342.   W := FindVCLWindow(P);
  343.   if (nil <> W) then
  344.   begin
  345.     while W.Parent <> nil do
  346.       W := W.Parent;
  347.     Result := W.Name;
  348.   end
  349.   else
  350.   begin
  351.     Result := '';
  352.   end;
  353. end;
  354. {------------------------------------------------------------------------------}
  355. {邮箱监测}
  356. function CheckPOP3Thread(Info: Pointer): Integer; stdcall;
  357. begin
  358.   LastMailCount := -1;
  359.   CurrentMailCount := -1;
  360.   while True do
  361.   begin
  362.     if RealMessengerX.ClientPOP3.Host <> '' then
  363.     begin
  364.       try
  365.         try
  366.           if RealMessengerX.ClientPOP3.Connected then RealMessengerX.ClientPOP3.Disconnect;
  367.           RealMessengerX.ClientPOP3.Connect();
  368.           LastMailCount := CurrentMailCount;
  369.           CurrentMailCount := RealMessengerX.ClientPOP3.CheckMessages;
  370.           RealMessengerX.LblMailCount.Caption := IntToStr(CurrentMailCount) + ' 封电子邮件';
  371.         except
  372.           LastMailCount := -1;
  373.           CurrentMailCount := -1;
  374.           RealMessengerX.LblMailCount.Caption := '未能连接至POP3服务器';
  375.         end;
  376.       finally
  377.         RealMessengerX.ClientPOP3.Disconnect;
  378.       end;
  379.     end
  380.     else
  381.     begin
  382.       RealMessengerX.LblMailCount.Caption := '点击设置您的邮箱';
  383.     end;
  384.     Sleep(60000);
  385.   end;
  386.   Result := 0;
  387. end;
  388. {------------------------------------------------------------------------------}
  389. {
  390. 功能:设置窗口样式(无标题栏,有边框)
  391. }
  392. {------------------------------------------------------------------------------}
  393. procedure TRealMessengerX.WMDEVICECHANGE(var msgx: Tmessage);
  394. const
  395.   DBT_DEVICEARRIVAL = $8000;
  396.   DBT_DEVICEREMOVECOMPLETE = $8004;
  397. begin
  398.   inherited;
  399.   if Me = nil then exit;
  400.   TestVideoDevice();
  401.   ChangeMyState(Me.State);
  402. end;
  403. {------------------------------------------------------------------------------}
  404. procedure TRealMessengerX.WMMOVE(var Msg: Tmessage);
  405. begin
  406. //
  407. end;
  408. {------------------------------------------------------------------------------}
  409. procedure TRealMessengerX.TestAudioDevice();
  410. begin
  411.   try
  412.     if Device.DeviceCount > 0 then
  413.       HaveAudioDevice := True
  414.     else
  415.       HaveAudioDevice := False;
  416.   except
  417.     HaveAudioDevice := False;
  418.   end;
  419. end;
  420. {------------------------------------------------------------------------------}
  421. procedure TRealMessengerX.TestVideoDevice();
  422. var
  423.   SysDev: TSysDevEnum;
  424. begin
  425.   SysDev := TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
  426.   if SysDev.CountFilters > 0 then
  427.     HaveVideoDevice := True
  428.   else
  429.     HaveVideoDevice := False;
  430.   SysDev.Free;
  431. end;
  432. {------------------------------------------------------------------------------}
  433. procedure TRealMessengerX.ActiveFormCreate(Sender: TObject);
  434. var
  435.   TempReg: TRegistry;
  436.   lgtick1, lgtick2: Int64;
  437. begin
  438.   queryperformancefrequency(performancefrequency_s);
  439.   performancefrequency_ms := performancefrequency_s / 1000;
  440.   //DoubleBuffered:=True;
  441.   try
  442.     InitCompressor;
  443.   finally
  444.     UnInitCompressor;
  445.   end;
  446.   MySockets := Classes.TThreadList.Create;
  447.   ReceivedMessages := Classes.TThreadList.Create;
  448.   MsgReturnCheck := Classes.TThreadList.Create;
  449.   Branchs := Classes.TThreadList.Create;
  450.   Employees := Classes.TThreadList.Create;
  451.   TransmitFiles := Classes.TThreadList.Create;
  452.   AudioHandShakes := Classes.TThreadList.Create;
  453.   VideoHandShakes := Classes.TThreadList.Create;
  454.   ChatingFormList := TList.Create;
  455.   MsgFormList := TList.Create;
  456.   MsgAlertQueue := TList.Create();
  457.   if ApplicationPath = '' then
  458.   begin
  459.     ApplicationPath := ExtractFilePath(Application.ExeName);
  460.     ResPath := ApplicationPath;
  461.     SoundPath := ApplicationPath + 'Sound';
  462.     CachePath := ApplicationPath + 'Cache';
  463.     HistoryPath := ApplicationPath + 'History';
  464.     PicPath := ApplicationPath + 'Pic';
  465.   end;
  466.   ImgListMain := ImglstTreeIcons;
  467.   TVMain := TrevUserList;
  468.   MACNO := GetNetBIOSAddress;
  469.   CoolTrayIcon.Hint := Application.Title + ' -- 未登录';
  470.   Caption := Application.Title;
  471.   TestAudioDevice();
  472.   TestVideoDevice();
  473.   TempReg := TRegistry.Create;
  474.   try
  475.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  476.     if TempReg.OpenKey(AppKey + 'FormStore', True) then
  477.     begin
  478.       Width := 218;
  479.       Height := Screen.WorkAreaHeight - (Screen.WorkAreaHeight div 3);
  480.       Left := Screen.WorkAreaWidth - 218;
  481.       top := (Screen.WorkAreaHeight - Height) div 2;
  482.       if trim(TempReg.ReadString('Left')) <> '' then Left := StrToInt(TempReg.ReadString('Left'));
  483.       if trim(TempReg.ReadString('Top')) <> '' then top := StrToInt(TempReg.ReadString('Top'));
  484.       if trim(TempReg.ReadString('Width')) <> '' then Width := StrToInt(TempReg.ReadString('Width'));
  485.       if trim(TempReg.ReadString('Height')) <> '' then Height := StrToInt(TempReg.ReadString('Height'));
  486.     end;
  487.     if TempReg.OpenKey(AppKey + 'Login', True) then
  488.     begin
  489.       LoginName := TempReg.ReadString('UserName');
  490.       Password := DESryStrHex(TempReg.ReadString('Password'), DESKEY);
  491.       if trim(TempReg.ReadString('LoginState')) = '' then TempReg.WriteString('LoginState', '联机');
  492.       LoginState := TempReg.ReadString('LoginState');
  493.       HostName := TempReg.ReadString('HostName');
  494.       HostToIP(HostName, HostIP);
  495.       if trim(TempReg.ReadString('ProxyCategory')) = '' then TempReg.WriteString('ProxyCategory', '0');
  496.       ProxyCategory := TProxyCategory(StrToInt(TempReg.ReadString('ProxyCategory')));
  497.       ProxyAddress := TempReg.ReadString('ProxyAddress');
  498.       if TempReg.ReadString('ProxyPort') = '' then TempReg.WriteString('ProxyPort', '1080');
  499.       ProxyPort := StrToInt(TempReg.ReadString('ProxyPort'));
  500.       ProxyUsername := TempReg.ReadString('ProxyUsername');
  501.       ProxyPassword := TempReg.ReadString('ProxyPassword');
  502.       if ProxyAddress <> '' then HostToIP(ProxyAddress, ProxyAddress);
  503.       if TempReg.ReadString('ServerPort') = '' then TempReg.WriteString('ServerPort', '0');
  504.       ServerPort := StrToInt(TempReg.ReadString('ServerPort'));
  505.       if TempReg.ReadString('MsgSound') = '' then TempReg.WriteString('MsgSound', SoundPath + 'Type.wav');
  506.       MsgSound := TempReg.ReadString('MsgSound');
  507.       if TempReg.ReadString('DontPlaySound') = '' then TempReg.WriteString('DontPlaySound', '0');
  508.       DontPlaySound := Boolean(StrToInt(TempReg.ReadString('DontPlaySound')));
  509.       if TempReg.ReadString('AutoConnectInterval') = '' then TempReg.WriteString('AutoConnectInterval', '180');
  510.       AutoConnectInterval := StrToInt(TempReg.ReadString('AutoConnectInterval'));
  511.       if TempReg.ReadString('DontAutoConnect') = '' then TempReg.WriteString('DontAutoConnect', '0');
  512.       DontAutoConnect := Boolean(StrToInt(TempReg.ReadString('DontAutoConnect')));
  513.       if (TempReg.ReadString('SavePass') = '1') and (LoginName <> '') and (HostName <> '') then
  514.       begin
  515.         GetInit();
  516.         SendIdentity();
  517.       end
  518.       else
  519.       begin
  520.         Login();
  521.       end;
  522.     end;
  523.   finally
  524.     TempReg.Free;
  525.   end;
  526. end;
  527. {------------------------------------------------------------------------------}
  528. procedure TRealMessengerX.GetListViewData(TV: TbsSkinTreeView; ViewStyle: TViewStyle = vsTree; IsForSelForm: Boolean = False);
  529. var
  530.   iLoop, jLoop, kLoop: Integer;
  531.   BranchPointer, TmpBranch: PBranch;
  532.   EmployeePointer: PEmployee;
  533.   TempReg: TRegistry;
  534.   Keys, Values: TStrings;
  535.   GroupNode: TTreeNode;
  536.   TempEmployees, TempBranchs: TThreadList;
  537. begin
  538.   OnlineNode := nil;
  539.   OfflineNode := nil;
  540.   if IsForSelForm then
  541.   begin
  542.     TempEmployees := TThreadList.Create;
  543.     TempBranchs := TThreadList.Create;
  544.     with Employees.LockList do
  545.     try
  546.       for iLoop := 0 to Count - 1 do
  547.       begin
  548.         GetMem(EmployeePointer, SizeOf(Employee));
  549.         CopyMemory(EmployeePointer, Items[iLoop], SizeOf(Employee));
  550.         TempEmployees.Add(EmployeePointer);
  551.       end;
  552.     finally
  553.       Employees.UnlockList;
  554.     end;
  555.     with Branchs.LockList do
  556.     try
  557.       for iLoop := 0 to Count - 1 do
  558.       begin
  559.         GetMem(BranchPointer, SizeOf(Employee));
  560.         CopyMemory(BranchPointer, Items[iLoop], SizeOf(Branch));
  561.         TempBranchs.Add(BranchPointer);
  562.       end;
  563.     finally
  564.       Branchs.UnlockList;
  565.     end;
  566.   end
  567.   else
  568.   begin
  569.     TempEmployees := Employees;
  570.     TempBranchs := Branchs;
  571.   end;
  572.   try
  573.     TV.Items.Clear;
  574.     if ViewStyle = vsTree then {显示树型方式}
  575.     begin
  576.       TV.ShowButtons := True;
  577.       TV.ShowLines := True;
  578.       with TempBranchs.LockList do
  579.       try
  580.         for iLoop := 0 to Count - 1 do {添加顶层部门列表}
  581.         begin
  582.           BranchPointer := Items[iLoop];
  583.           BranchPointer.Node := TV.Items.AddChildObject(nil, BranchPointer.Name, BranchPointer);
  584.           BranchPointer.Node.StateIndex := 1 {1表示为部门};
  585.         end; //for
  586.         for iLoop := 0 to Count - 1 do {添加子部门列表}
  587.         begin
  588.           BranchPointer := Items[iLoop];
  589.           for jLoop := 0 to Count - 1 do
  590.           begin
  591.             TmpBranch := Items[jLoop];
  592.             if BranchPointer.ParentID = TmpBranch.ID then
  593.             begin
  594.               BranchPointer.Node.MoveTo(TmpBranch.Node, naAddChild);
  595.               TmpBranch.Node.Expanded := False;
  596.               break;
  597.             end;
  598.           end;
  599.         end;
  600.       finally
  601.         TempBranchs.UnlockList;
  602.       end;
  603.       with TempEmployees.LockList do
  604.       try
  605.         for iLoop := Count - 1 downto 0 do {添加用户列表}
  606.         begin
  607.           EmployeePointer := Items[iLoop];
  608.           with TempBranchs.LockList do
  609.           try
  610.             for jLoop := 0 to Count - 1 do
  611.             begin
  612.               if (PBranch(Items[jLoop])^.ID = EmployeePointer.BranchID) then
  613.               begin
  614.                 EmployeePointer.Node := TV.Items.AddChildObjectFirst(PBranch(Items[jLoop])^.Node, EmployeePointer.Name, EmployeePointer);
  615.                 EmployeePointer.Node.StateIndex := 2 {2表示为用户};
  616.                 UpdateListViewStates(TV, EmployeePointer.Node); {更新用户状态}
  617.                 break;
  618.               end;
  619.             end; //for
  620.           finally
  621.             TempBranchs.UnlockList;
  622.           end;
  623.         end; //for
  624.       finally
  625.         TempEmployees.UnlockList;
  626.       end;
  627.       if not IsForSelForm then Me.Node.MakeVisible; {展开当前户名所在的节点}
  628.     end;
  629.     if ViewStyle = vsOnlineOffline then
  630.     begin
  631.       TV.ShowButtons := False;
  632.       TV.ShowLines := False;
  633.       OnlineNode := TV.Items.AddChild(nil, '联机');
  634.       OnlineNode.StateIndex := -1;
  635.       OfflineNode := TV.Items.AddChild(nil, '没有联机');
  636.       OfflineNode.StateIndex := -1;
  637.       with TempEmployees.LockList do
  638.       try
  639.         for iLoop := 0 to Count - 1 do
  640.         begin
  641.           EmployeePointer := Items[iLoop];
  642.           EmployeePointer.Node := TV.Items.AddChildObject(OfflineNode, EmployeePointer.Name, EmployeePointer);
  643.           EmployeePointer.Node.StateIndex := 2;
  644.           UpdateListViewStates(TV, EmployeePointer.Node)
  645.         end;
  646.       finally
  647.         TempEmployees.UnlockList;
  648.       end;
  649.       OfflineNode.Expanded := True;
  650.     end;
  651.     if ViewStyle = vsGroup then {显示组方式}
  652.     begin
  653.       TV.ShowButtons := False;
  654.       TV.ShowLines := False;
  655.       with TempEmployees.LockList do
  656.       try
  657.         for iLoop := 0 to Count - 1 do
  658.         begin
  659.           EmployeePointer := Items[iLoop];
  660.           EmployeePointer.Node := nil;
  661.         end;
  662.       finally
  663.         TempEmployees.UnlockList;
  664.       end;
  665.       TempReg := TRegistry.Create;
  666.       try
  667.         TempReg.RootKey := HKEY_LOCAL_MACHINE;
  668.         if not TempReg.KeyExists(AppKey + '' + LoginName + 'Group') then
  669.         begin
  670.           if TempReg.OpenKey(AppKey + '' + LoginName + 'Group本部门', True) then
  671.           begin
  672.             with TempEmployees.LockList do
  673.             try
  674.               for iLoop := 0 to Count - 1 do
  675.               begin
  676.                 EmployeePointer := Items[iLoop];
  677.                 if EmployeePointer.BranchID = Me.BranchID then TempReg.WriteString(IntToStr(EmployeePointer.ID), EmployeePointer.LoginName);
  678.               end;
  679.             finally
  680.               TempEmployees.UnlockList;
  681.             end;
  682.           end;
  683.         end;
  684.         if TempReg.OpenKey(AppKey + '' + LoginName + 'Group', True) then
  685.         begin
  686.           Keys := TStringList.Create;
  687.           TempReg.GetKeyNames(Keys);
  688.           for iLoop := 0 to Keys.Count - 1 do
  689.           begin
  690.             GroupNode := TV.Items.AddChild(nil, Keys.Strings[iLoop]);
  691.             GroupNode.StateIndex := -1; {-1表示自定义组方式}
  692.             if TempReg.OpenKey(AppKey + '' + LoginName + 'Group' + Keys.Strings[iLoop], True) then
  693.             begin
  694.               Values := TStringList.Create;
  695.               TempReg.GetValueNames(Values);
  696.               for jLoop := 0 to Values.Count - 1 do
  697.               begin
  698.                 with TempEmployees.LockList do
  699.                 try
  700.                   for kLoop := 0 to Count - 1 do
  701.                   begin
  702.                     EmployeePointer := Items[kLoop];
  703.                     if EmployeePointer.ID = StrToInt(Values.Strings[jLoop]) then
  704.                     begin
  705.                       EmployeePointer.Node := TV.Items.AddChildObject(GroupNode, EmployeePointer.Name, EmployeePointer);
  706.                       EmployeePointer.Node.StateIndex := 2 {2表示为用户};
  707.                       UpdateListViewStates(TV, EmployeePointer.Node); {更新用户状态}
  708.                     end;
  709.                   end;
  710.                 finally
  711.                   TempEmployees.UnlockList
  712.                 end;
  713.               end; //for
  714.               Values.Free;
  715.             end; //if
  716.             GroupNode.Expanded := True;
  717.           end; //for
  718.           Keys.Free;
  719.         end; //if
  720.       finally
  721.         TempReg.Free;
  722.       end;
  723.     end;
  724.     if TV.Items.GetFirstNode <> nil then TV.Items.GetFirstNode.Selected := True;
  725.     if TV.Items.GetFirstNode <> nil then TV.Items.GetFirstNode.Selected := False;
  726.   finally
  727.     if IsForSelForm then
  728.     begin
  729.       TempEmployees.Clear;
  730.       TempEmployees.Free;
  731.       TempBranchs.Clear;
  732.       TempBranchs.Free;
  733.     end;
  734.   end;
  735. end;
  736. {------------------------------------------------------------------------------}
  737. {更改当前用户的显示状态}
  738. procedure TRealMessengerX.ChangeLblMyStateCaption();
  739. var
  740.   iLoop, jLoop, GBBytes, IconIndex: Integer;
  741.   ShowName: string;
  742. begin
  743.   if Me <> nil then
  744.   begin
  745.     LblMyState.Caption := Me.Name + '(' + Me.State + ')';
  746.     CoolTrayIcon.Hint := Application.Title + ' -- ' + Me.Name + '(' + Me.State + ')';
  747.     IconIndex := 2;
  748.     NS8.Checked := True;
  749.     MOther.Checked := True;
  750.     if Me.State = '断开' then
  751.     begin
  752.       IconIndex := 0;
  753.       NS8.Checked := False;
  754.       MOther.Checked := False;
  755.     end;
  756.     if Me.State = '显示为脱机' then
  757.     begin
  758.       IconIndex := 4;
  759.       NS9.Checked := True;
  760.       MOffline.Checked := True;
  761.     end;
  762.     if Me.State = '联机' then
  763.     begin
  764.       IconIndex := 1;
  765.       NS1.Checked := True;
  766.       MOnline.Checked := True;
  767.     end;
  768.     if Me.State = '忙碌' then
  769.     begin
  770.       IconIndex := 3;
  771.       NS2.Checked := True;
  772.       MBusy.Checked := True;
  773.     end;
  774.     if Me.State = '马上回来' then
  775.     begin
  776.       IconIndex := 2;
  777.       NS3.Checked := True;
  778.       MWillBack.Checked := True;
  779.     end;
  780.     if Me.State = '离开' then
  781.     begin
  782.       IconIndex := 2;
  783.       NS4.Checked := True;
  784.       MLeave.Checked := True;
  785.     end;
  786.     if Me.State = '接听电话' then
  787.     begin
  788.       IconIndex := 3;
  789.       NS5.Checked := True;
  790.       MPhone.Checked := True;
  791.     end;
  792.     if Me.State = '外出就餐' then
  793.     begin
  794.       IconIndex := 2;
  795.       NS6.Checked := True;
  796.       MRepast.Checked := True;
  797.     end;
  798.     if Me.State = '参加会议' then
  799.     begin
  800.       IconIndex := 3;
  801.       NS7.Checked := True;
  802.       NMeeting.Checked := True;
  803.     end;
  804.   end
  805.   else
  806.   begin
  807.     LblMyState.Caption := '未登录';
  808.     CoolTrayIcon.Hint := Application.Title + ' -- 未登录';
  809.     IconIndex := 0;
  810.   end;
  811.   if not CoolTrayIcon.CycleIcons then ImgLstTrayIcon.GetIcon(IconIndex, CoolTrayIcon.Icon);
  812.   if Me = nil then exit;
  813.   iLoop := 1;
  814.   while (LblMyState.Canvas.TextWidth(LblMyState.Caption) > LblMyState.Width) and (iLoop < Length(Me.Name)) do
  815.   begin
  816.     ShowName := Copy(Me.Name, 1, Length(Me.Name) - iLoop);
  817.     GBBytes := 0;
  818.     for jLoop := 1 to Length(ShowName) do
  819.     begin
  820.       if Ord(ShowName[jLoop]) > 128 then Inc(GBBytes);
  821.     end;
  822.     if GBBytes mod 2 <> 0 then ShowName := Copy(ShowName, 1, Length(ShowName) - 1);
  823.     LblMyState.Caption := ShowName + ' ...(' + Me.State + ')';
  824.     Inc(iLoop);
  825.   end;
  826. end;
  827. {------------------------------------------------------------------------------}
  828. procedure TRealMessengerX.UpdateMyState();
  829. begin
  830.   ChangeLblMyStateCaption();
  831. end;
  832. {------------------------------------------------------------------------------}
  833. procedure TRealMessengerX.UpdateListViewStates(TV: TbsSkinTreeView; Node: TTreeNode);
  834. var
  835.   BaseImageIndex: Integer;
  836.   Employee: PEmployee;
  837. begin
  838.   try
  839.     if Node = nil then exit;
  840.     Employee := Node.Data;
  841.     BaseImageIndex := 6;
  842.     Employee.Node.Text := '';
  843.     Employee.Node.ImageIndex := BaseImageIndex;
  844.     if (AnsiSameText(Employee.State, '显示为脱机') or AnsiSameStr(Employee.State, '断开')) then
  845.     begin
  846.       Employee.Node.ImageIndex := BaseImageIndex;
  847.       Employee.Node.Text := Employee.Name;
  848.       if (Employee.Node.Parent <> nil) and (Employee.Node.Parent = OnlineNode) then
  849.       begin
  850.         try
  851.           Employee.Node.MoveTo(OfflineNode, naAddChildFirst);
  852.           if OfflineNode.Count > 0 then OfflineNode.Expanded := True;
  853.         except
  854.         end;
  855.       end;
  856.       exit;
  857.     end;
  858.     if (Employee.Node.Parent = OfflineNode) then
  859.     begin
  860.       try
  861.         Employee.Node.MoveTo(OnlineNode, naAddChildFirst);
  862.         if OnlineNode.Count > 0 then OnlineNode.Expanded := True;
  863.       except
  864.       end;
  865.     end;
  866.     if AnsiSameText(Employee.State, '联机') then
  867.     begin
  868.       Employee.Node.ImageIndex := BaseImageIndex + 1;
  869.       Employee.Node.Text := Employee.Name;
  870.       exit;
  871.     end;
  872.     if AnsiSameText(Employee.State, '忙碌') then
  873.     begin
  874.       Employee.Node.ImageIndex := BaseImageIndex + 3;
  875.       Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  876.       exit;
  877.     end;
  878.     if AnsiSameText(Employee.State, '马上回来') then
  879.     begin
  880.       Employee.Node.ImageIndex := BaseImageIndex + 2;
  881.       Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  882.       exit;
  883.     end;
  884.     if AnsiSameText(Employee.State, '离开') then
  885.     begin
  886.       Employee.Node.ImageIndex := BaseImageIndex + 2;
  887.       Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  888.       exit;
  889.     end;
  890.     if AnsiSameText(Employee.State, '接听电话') then
  891.     begin
  892.       Employee.Node.ImageIndex := BaseImageIndex + 3;
  893.       Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  894.       exit;
  895.     end;
  896.     if AnsiSameText(Employee.State, '外出就餐') then
  897.     begin
  898.       Employee.Node.ImageIndex := BaseImageIndex + 2;
  899.       Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  900.       exit;
  901.     end;
  902.     if AnsiSameText(Employee.State, '参加会议') then
  903.     begin
  904.       Employee.Node.ImageIndex := BaseImageIndex + 3;
  905.       Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  906.       exit;
  907.     end;
  908.     Employee.Node.ImageIndex := BaseImageIndex + 2;
  909.     Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
  910.   finally
  911.     //TV.Refresh
  912.   end;
  913. end;
  914. {------------------------------------------------------------------------------}
  915. procedure TRealMessengerX.TrevUserListGetImageIndex(Sender: TObject;
  916.   Node: TTreeNode);
  917. begin
  918.   if Node.StateIndex = -1 then
  919.   begin
  920.     if Node.Expanded then
  921.       Node.ImageIndex := 4
  922.     else
  923.       Node.ImageIndex := 5;
  924.   end;
  925.   if Node.StateIndex = 0 then
  926.   begin
  927.     if Node.Expanded then
  928.       Node.ImageIndex := 1
  929.     else
  930.       Node.ImageIndex := 0;
  931.   end;
  932.   if Node.StateIndex = 1 then
  933.   begin
  934.     if Node.Expanded then
  935.       Node.ImageIndex := 3
  936.     else
  937.       Node.ImageIndex := 2;
  938.   end;
  939.   Node.SelectedIndex := Node.ImageIndex;
  940. end;
  941. {------------------------------------------------------------------------------}
  942. procedure TRealMessengerX.TrevUserListCustomDrawItem(
  943.   Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState;
  944.   var DefaultDraw: Boolean);
  945. begin
  946.   DefaultDraw := True;
  947.   if Node.Selected then
  948.   begin
  949.     TrevUserList.Canvas.Font.Color := clWhite;
  950.   end
  951.   else
  952.   begin
  953.     if Node.StateIndex = 2 then
  954.     begin
  955.       if (Node.ImageIndex = 6) or (Node.ImageIndex = 10) then
  956.         TrevUserList.Canvas.Font.Color := clRed
  957.       else
  958.         TrevUserList.Canvas.Font.Color := clGreen;
  959.     end
  960.     else if Node.StateIndex = -1 then
  961.     begin
  962.       TrevUserList.Canvas.Font.Color := $00934A46;
  963.       TrevUserList.Canvas.Font.Style := [fsBold];
  964.     end
  965.     else
  966.       TrevUserList.Canvas.Font.Color := clBlack;
  967.   end;
  968.   TrevUserList.Canvas.Textout(Node.DisplayRect(True).Left + 2, Node.DisplayRect(True).top + 2, Node.Text);
  969. end;
  970. {------------------------------------------------------------------------------}
  971. procedure TRealMessengerX.Login();
  972. var
  973.   LoginForm: TLoginForm;
  974.   TempReg: TRegistry;
  975. begin
  976.   LoginForm := TLoginForm.Create(Application);
  977.   try
  978.     TempReg := TRegistry.Create;
  979.     try
  980.       TempReg.RootKey := HKEY_LOCAL_MACHINE;
  981.       if TempReg.OpenKey(AppKey + 'Login', True) then
  982.       begin
  983.         LoginForm.EDUserName.Text := TempReg.ReadString('UserName');
  984.         if LoginForm.ShowModal <> mrOK then exit;
  985.         Show;
  986.         TempReg.WriteString('UserName', trim(LoginForm.EDUserName.Text));
  987.         if LoginForm.CBSavePass.Checked then
  988.         begin
  989.           TempReg.WriteString('SavePass', '1');
  990.           TempReg.WriteString('Password', EncryStrHex(trim(LoginForm.EDPassword.Text), DESKEY));
  991.           TempReg.WriteString('LoginState', trim(LoginForm.CBState.Text));
  992.         end
  993.         else
  994.         begin
  995.           TempReg.WriteString('SavePass', '0');
  996.           TempReg.WriteString('Password', '');
  997.           TempReg.WriteString('LoginState', '联机');
  998.         end;
  999.         LoginName := trim(LoginForm.EDUserName.Text);
  1000.         Password := trim(LoginForm.EDPassword.Text);
  1001.         LoginState := trim(LoginForm.CBState.Text);
  1002.       end;
  1003.     finally
  1004.       TempReg.Free;
  1005.     end;
  1006.     GetInit();
  1007.     SendIdentity();
  1008.   finally
  1009.     LoginForm.Free;
  1010.   end;
  1011. end;
  1012. {------------------------------------------------------------------------------}
  1013. {点击了登录菜单}
  1014. procedure TRealMessengerX.MConnectClick(Sender: TObject);
  1015. begin
  1016.   if MConnect.Caption = '取消登录(&I)' then
  1017.   begin
  1018.     ClientLogout();
  1019.   end
  1020.   else
  1021.   begin
  1022.     TimerAutoConnect.Enabled := False;
  1023.     Login();
  1024.   end;
  1025. end;
  1026. {------------------------------------------------------------------------------}
  1027. procedure TRealMessengerX.ClientLogin();
  1028. var
  1029.   ThreadId: DWORD;
  1030. begin
  1031.   if CheckPOP3ThreadHandle = 0 then CheckPOP3ThreadHandle := CreateThread(nil, 0, @CheckPOP3Thread, nil, 0, ThreadId);
  1032.   LblMailCount.Enabled := True;
  1033.   TimerAutoConnect.Enabled := False;
  1034.   TimerLoging.Enabled := False;
  1035.   PBLogin.Visible := False;
  1036.   LblLoging.Visible := False;
  1037.   LblCancelLogin.Visible := False;
  1038.   TrevUserList.Show;
  1039.   if MAutoLeave.Checked or MAutoBusy.Checked then
  1040.   begin
  1041.     STimer.Enabled := True;
  1042.     Snoop := 0;
  1043.   end;
  1044.   ConnectedTicket := GetTickCount;
  1045.   MConnect.Enabled := False;
  1046.   MConnect.Caption := '登录(&I)';
  1047.   MConnectSet.Enabled := True;
  1048.   MDisconnect.Enabled := True;
  1049.   MMyState.Enabled := True;
  1050.   MSendMsg.Enabled := True;
  1051.   MSendFile.Enabled := True;
  1052.   MSendVoice.Enabled := True;
  1053.   MSendVideo.Enabled := True;
  1054.   MShowHistory.Enabled := True;
  1055.   //MChangeNameAndPassword.Enabled :=True;
  1056.   NR1.Enabled := True;
  1057.   NR2.Enabled := True;
  1058.   NR3.Enabled := True;
  1059.   NR4.Enabled := True;
  1060.   NR5.Enabled := True;
  1061.   HartTimer.Enabled := True;
  1062.   KeepP2PSessionTimer.Enabled := True;
  1063.   LastReturnHartTick := GetTickCount;
  1064.   GetListViewData(TrevUserList, vsTree);
  1065.   if Me <> nil then
  1066.   begin
  1067.     UpdateMyState;
  1068.     CoolTrayIcon.ShowBalloonHint('登录成功', '您好:' + Me.Name + #13 + '您已登录至 ' + Application.Title + ' 服务器!', bitInfo, 10);
  1069.   end;
  1070. end;
  1071. {------------------------------------------------------------------------------}
  1072. procedure TRealMessengerX.ClientLogout();
  1073. var
  1074.   iLoop: Integer;
  1075.   EmployeePointer: PEmployee;
  1076.   ChatingForm: TChatingForm;
  1077.   AudioHandShake: TAudioHandShake;
  1078.   VideoHandShake: TVideoHandShake;
  1079.   TransmitFile: TTransmitFile;
  1080.   MySocket: TMySocket;
  1081. begin
  1082.   if ClientTCP.Connected then
  1083.   begin
  1084.     ClientTCP.OnDisconnected := nil;
  1085.     ClientTCP.Disconnect;
  1086.   end;
  1087.   if CheckPOP3ThreadHandle <> 0 then TerminateThread(CheckPOP3ThreadHandle, 4);
  1088.   CheckPOP3ThreadHandle := 0;
  1089.   LblMailCount.Caption := '0 封电子邮件';
  1090.   LblMailCount.Enabled := False;
  1091.   TimerAutoConnect.Enabled := False;
  1092.   TimerLoging.Enabled := False;
  1093.   KeepP2PSessionTimer.Enabled := False;
  1094.   PBLogin.Visible := False;
  1095.   LblLoging.Visible := False;
  1096.   LblCancelLogin.Visible := False;
  1097.   CoolTrayIcon.CycleIcons := False;
  1098.   MsgAlertQueue.Clear;
  1099.   TrevUserList.Hide;
  1100.   STimer.Enabled := False;
  1101.   MConnect.Enabled := True;
  1102.   MConnect.Caption := '登录(&I)';
  1103.   MConnectSet.Enabled := True;
  1104.   MDisconnect.Enabled := False;
  1105.   MMyState.Enabled := False;
  1106.   MSendMsg.Enabled := False;
  1107.   MSendFile.Enabled := False;
  1108.   MSendVoice.Enabled := False;
  1109.   MSendVideo.Enabled := False;
  1110.   MShowHistory.Enabled := False;
  1111.   MChangeNameAndPassword.Enabled := False;
  1112.   NR1.Enabled := False;
  1113.   NR2.Enabled := False;
  1114.   NR3.Enabled := False;
  1115.   NR4.Enabled := False;
  1116.   NR5.Enabled := False;
  1117.   HartTimer.Enabled := False;
  1118.   for iLoop := ChatingFormList.Count - 1 downto 0 do
  1119.   begin
  1120.     ChatingForm := ChatingFormList.Items[iLoop];
  1121.     ChatingFormList.Remove(ChatingForm);
  1122.     try
  1123.       if (ChatingForm is TChatingForm) then ChatingForm.Free;
  1124.     except
  1125.     end;
  1126.   end;
  1127.   with VideoHandShakes.LockList do
  1128.   try
  1129.     for iLoop := Count - 1 downto 0 do
  1130.     begin
  1131.       VideoHandShake := Items[iLoop];
  1132.       VideoHandShake.Free;
  1133.       VideoHandShakes.Remove(VideoHandShake);
  1134.     end;
  1135.   finally
  1136.     VideoHandShakes.UnlockList;
  1137.   end;
  1138.   with AudioHandShakes.LockList do
  1139.   try
  1140.     for iLoop := Count - 1 downto 0 do
  1141.     begin
  1142.       AudioHandShake := Items[iLoop];
  1143.       AudioHandShake.Free;
  1144.       AudioHandShakes.Remove(AudioHandShake);
  1145.     end;
  1146.   finally
  1147.     AudioHandShakes.UnlockList;
  1148.   end;
  1149.   with TransmitFiles.LockList do
  1150.   try
  1151.     for iLoop := Count - 1 downto 0 do
  1152.     begin
  1153.       TransmitFile := Items[iLoop];
  1154.       TransmitFile.Free;
  1155.       TransmitFiles.Remove(TransmitFile);
  1156.     end;
  1157.   finally
  1158.     TransmitFiles.UnlockList;
  1159.   end;
  1160.   with Employees.LockList do
  1161.   try
  1162.     for iLoop := 0 to Count - 1 do
  1163.     begin
  1164.       EmployeePointer := Items[iLoop];
  1165.       EmployeePointer.State := '断开';
  1166.       EmployeePointer.HaveAudioDevice := False;
  1167.       EmployeePointer.HaveVideoDevice := False;
  1168.       UpdateListViewStates(TrevUserList, EmployeePointer.Node); {更新用户状态}
  1169.       FreeMem(EmployeePointer, SizeOf(Employee));
  1170.     end;
  1171.   finally
  1172.     Employees.UnlockList;
  1173.   end;
  1174.   Employees.Clear;
  1175.   with Branchs.LockList do
  1176.   try
  1177.     for iLoop := 0 to Count - 1 do FreeMem(Items[iLoop], SizeOf(Branch));
  1178.   finally
  1179.     Branchs.UnlockList;
  1180.   end;
  1181.   Branchs.Clear;
  1182.   UpdateMyState();
  1183.   TrevUserList.Items.Clear;
  1184.   Me := nil;
  1185.   if not DontAutoConnect then
  1186.   begin
  1187.     TimerAutoConnect.Interval := AutoConnectInterval * 1000;
  1188.     TimerAutoConnect.Enabled := True;
  1189.   end;
  1190.   with MySockets.LockList do
  1191.   try
  1192.     for iLoop := Count - 1 downto 0 do
  1193.     begin
  1194.       try
  1195.         MySocket := Items[iLoop];
  1196.         MySocket.Free;
  1197.         MySocket := nil;
  1198.       except
  1199.       end;
  1200.     end;
  1201.   finally
  1202.     MySockets.UnlockList;
  1203.   end;
  1204. end;
  1205. {------------------------------------------------------------------------------}
  1206. procedure TRealMessengerX.SendIdentity;
  1207. var
  1208.   LoginTime: Integer;
  1209.   CBLogin: TCBLogin;
  1210.   Buffer: array[1..2048] of char;
  1211.   StrHttpProxySend, StrHttpProxyRecive: string;
  1212. begin
  1213.   if ClientTCP.Connected = False then
  1214.   begin
  1215.    //  showmessage(trim(SystemSetForm.EDHostName.Text));
  1216.    // showmessage(SystemSetForm.EDHostName.Text);
  1217.     if inet_addr(PChar(HostIP))=INADDR_NONE then
  1218.       ClientTCP.Host:=HostName
  1219.     else
  1220.       ClientTCP.Host:=HostIP;
  1221.     ClientTCP.Port:=ServerPort;
  1222.     {ClientTCP.Host := trim(SystemSetForm.EDHostName.Text);
  1223.     ClientTCP.Port := StrToInt(SystemSetForm.EDHostName.Text);}
  1224.     try
  1225.       MConnect.Caption := '取消登录(&I)';
  1226.       Gauge.Progress := 0;
  1227.       PBLogin.Visible := True;
  1228.       LblLoging.Caption := '正在连接...';
  1229.       LblLoging.Visible := True;
  1230.       LblCancelLogin.Visible := True;
  1231.       if ProxyCategory <> pcHTTP then
  1232.       begin
  1233.         IdSocksInfo1.Version := TSocksVersion(ProxyCategory);
  1234.         IdSocksInfo1.Host := ProxyAddress;
  1235.         IdSocksInfo1.Port := ProxyPort;
  1236.         if ProxyUsername = '' then
  1237.         begin
  1238.           IdSocksInfo1.Authentication := saNoAuthentication;
  1239.         end
  1240.         else
  1241.         begin
  1242.           IdSocksInfo1.Authentication := saUsernamePassword;
  1243.           IdSocksInfo1.Username := ProxyUsername;
  1244.           IdSocksInfo1.Password := ProxyPassword;
  1245.         end;
  1246.         LoginTime := 0;
  1247.         while LoginTime < 3 do
  1248.         try
  1249.           ClientTCP.Connect(8000);
  1250.           break;
  1251.         except
  1252.           Inc(LoginTime);
  1253.         end;
  1254.       end
  1255.       else
  1256.       begin
  1257.         IdSocksInfo1.Version := svNoSocks;
  1258.         StrHttpProxySend := Format('CONNECT %s:%d HTTP/1.0'#$d#$a#$d#$a + 'Host %s'#$d#$a, [ClientTCP.Host, ClientTCP.Port, ClientTCP.Host]);
  1259.         ClientTCP.Host := ProxyAddress;
  1260.         ClientTCP.Port := ProxyPort;
  1261.         ClientTCP.Connect(8000);
  1262.         ClientTCP.Write(StrHttpProxySend);
  1263.         StrHttpProxyRecive := ClientTCP.ReadLn; //(EOL);
  1264.         ClientTCP.ReadLn;
  1265.         ClientTCP.ReadLn;
  1266.         if Copy(StrHttpProxyRecive, 1, 12) <> 'HTTP/1.0 200' then ClientTCP.Disconnect;
  1267.       end;
  1268.     except
  1269.     end;
  1270.     if not ClientTCP.Connected then
  1271.     begin
  1272.       ClientLogout;
  1273.       CoolTrayIcon.ShowBalloonHint('连接失败', '未能连接至服务器,请检查网络设置!', bitError, 10);
  1274.       exit;
  1275.     end;
  1276.     ClientHandleThread := TClientHandleThread.Create;
  1277.     ClientHandleThread.FreeOnTerminate := True;
  1278.     ClientHandleThread.Resume;
  1279.   end;
  1280.   CBLogin.LoginName := LoginName;
  1281.   CBLogin.Password := Password;
  1282.   CBLogin.State := LoginState;
  1283.   CBLogin.LocalIP := GetHostIP('');
  1284.   CBLogin.LocalPort := ClientTCP.Socket.Binding.Port;
  1285.   CBLogin.HaveAudioDevice := HaveAudioDevice;
  1286.   CBLogin.HaveVideoDevice := HaveVideoDevice;
  1287.   CBLogin.MACNO := MACNO;
  1288.   CBLogin.Version := 40000;
  1289.   Buffer[1] := skLogin;
  1290.   CopyMemory(@Buffer[2], @CBLogin, SizeOf(CBLogin));
  1291.   ClientTCP.Socket.Send(Buffer, SizeOf(CBLogin) + 1);
  1292.   LblMyState.Caption := '正在登录...';
  1293. end;
  1294. {------------------------------------------------------------------------------}
  1295. procedure TRealMessengerX.GetInit();
  1296. var
  1297.   TempReg: TRegistry;
  1298.   ID: string;
  1299. begin
  1300.   ID := LoginName;
  1301.   TempReg := TRegistry.Create;
  1302.   try
  1303.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1304.     if TempReg.OpenKey(AppKey + '' + ID + 'Init', True) then
  1305.     begin
  1306.       if trim(TempReg.ReadString('ViewStyle')) = '' then
  1307.         TempReg.WriteString('ViewStyle', 'Tree');
  1308.       if trim(TempReg.ReadString('HiddenState')) = '' then
  1309.         TempReg.WriteString('HiddenState', '0');
  1310.       if trim(TempReg.ReadString('AutoLeave')) = '' then
  1311.         TempReg.WriteString('AutoLeave', '1');
  1312.       if trim(TempReg.ReadString('AutoBusy')) = '' then
  1313.         TempReg.WriteString('AutoBusy', '1');
  1314.       if StrToInt(TempReg.ReadString('AutoLeave')) = 0 then MAutoLeave.Checked := False;
  1315.       if StrToInt(TempReg.ReadString('AutoBusy')) = 0 then MAutoBusy.Checked := False;
  1316.       if TempReg.ReadString('CustomColor') <> '' then
  1317.       begin
  1318.         EndColor := TColor(StrToInt(TempReg.ReadString('CustomColor')));
  1319.         ChangeAllColor(EndColor);
  1320.       end
  1321.       else begin
  1322.         EndColor := TColor(13816530);
  1323.         ChangeAllColor(EndColor);
  1324.       end;
  1325.       if TempReg.ReadString('POP3Server') <> '' then
  1326.       begin
  1327.         ClientPOP3.Host := TempReg.ReadString('POP3Server');
  1328.         ClientPOP3.Port := StrToInt(TempReg.ReadString('POP3Port'));
  1329.         ClientPOP3.Username := TempReg.ReadString('POP3User');
  1330.         ClientPOP3.Password := DESryStrHex(TempReg.ReadString('POP3Pass'), DESKEY);
  1331.       end
  1332.       else
  1333.       begin
  1334.         LblMailCount.Caption := '点击设置您的邮箱';
  1335.       end;
  1336.     end;
  1337.   finally
  1338.     TempReg.Free;
  1339.   end;
  1340. end;
  1341. {------------------------------------------------------------------------------}
  1342. {选择了树型方式查看部门及用户列表}
  1343. procedure TRealMessengerX.MTreeClick(Sender: TObject);
  1344. var
  1345.   TempReg: TRegistry;
  1346. begin
  1347.   TempReg := TRegistry.Create;
  1348.   try
  1349.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1350.     if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then TempReg.WriteString('ViewStyle', 'Tree');
  1351.   finally
  1352.     TempReg.Free;
  1353.   end;
  1354.   GetListViewData(TrevUserList, vsTree);
  1355. end;
  1356. {------------------------------------------------------------------------------}
  1357. {选择了联机/脱机方式查看部门及用户列表}
  1358. procedure TRealMessengerX.MOnOrOffClick(Sender: TObject);
  1359. var
  1360.   TempReg: TRegistry;
  1361. begin
  1362.   TempReg := TRegistry.Create;
  1363.   try
  1364.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1365.     if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then TempReg.WriteString('ViewStyle', 'OnOrOff');
  1366.   finally
  1367.     TempReg.Free;
  1368.   end;
  1369.   GetListViewData(TrevUserList, vsOnlineOffline);
  1370. end;
  1371. {------------------------------------------------------------------------------}
  1372. procedure TRealMessengerX.MGroupClick(Sender: TObject);
  1373. var
  1374.   TempReg: TRegistry;
  1375. begin
  1376.   TempReg := TRegistry.Create;
  1377.   try
  1378.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1379.     if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then TempReg.WriteString('ViewStyle', 'Group');
  1380.   finally
  1381.     TempReg.Free;
  1382.   end;
  1383.   GetListViewData(TrevUserList, vsGroup);
  1384. end;
  1385. {------------------------------------------------------------------------------}
  1386. procedure TRealMessengerX.ChangeMyState(State: string; IsAutoState: Boolean = False);
  1387. var
  1388.   CBStateChanged: TCBStateChanged;
  1389.   Buffer: array[1..2048] of char;
  1390. begin
  1391.   CBStateChanged.ID := Me.ID;
  1392.   CBStateChanged.State := State;
  1393.   CBStateChanged.HaveAudioDevice := HaveAudioDevice;
  1394.   CBStateChanged.HaveVideoDevice := HaveVideoDevice;
  1395.   CBStateChanged.IsAutoState := IsAutoState;
  1396.   Buffer[1] := skStateChanged;
  1397.   CopyMemory(@Buffer[2], @CBStateChanged, SizeOf(CBStateChanged));
  1398.   try
  1399.     ClientTCP.WriteBuffer(Buffer, SizeOf(CBStateChanged) + 1, True);
  1400.   except
  1401.     MessageBox(Handle, '更改状态失败!', '错误', MB_ICONERROR);
  1402.     ClientLogout;
  1403.   end;
  1404. end;
  1405. {------------------------------------------------------------------------------}
  1406. procedure TRealMessengerX.MOfflineClick(Sender: TObject);
  1407. begin
  1408.   ChangeMyState(Copy(trim((Sender as TMenuItem).Caption), 1, Length(trim((Sender as TMenuItem).Caption)) - 4));
  1409. end;
  1410. {------------------------------------------------------------------------------}
  1411. {用户要自己输入状态值}
  1412. procedure TRealMessengerX.MOtherClick(Sender: TObject);
  1413. var
  1414.   InputState: string;
  1415. begin
  1416.   InputState := trim(ShowMyInputBox('输入', '您要将当前的状态更改为:', '', 20));
  1417.   if Length(InputState) > 0 then
  1418.   begin
  1419.     ChangeMyState(InputState);
  1420.   end;
  1421. end;
  1422. {------------------------------------------------------------------------------}
  1423. procedure TRealMessengerX.FlashTray(ChatingForm: TChatingForm);
  1424. begin
  1425.   if ChatingForm.Visible then exit;
  1426.   if ChatingForm.Pushed then exit;
  1427.   ChatingForm.Pushed := True;
  1428.   MsgAlertQueue.Add(ChatingForm);
  1429.   CoolTrayIcon.IconList := ImgLstMsgAlert;
  1430.   CoolTrayIcon.CycleIcons := True;
  1431. end;
  1432. {------------------------------------------------------------------------------}
  1433. procedure TRealMessengerX.ShowImage(PHandle: HWND; BitMap: HBitMap; Buf: PByte);
  1434.   procedure SetImage(HBitMap: THandle);
  1435.   begin
  1436.     SendMessage(BitMap, STM_SETIMAGE, IMAGE_BITMAP, Integer(HBitMap));
  1437.   end;
  1438. var
  1439.   pData: Pointer;
  1440.   pDC, MemDC: THandle;
  1441.   HBitMap: THandle;
  1442. begin
  1443.   pDC := GetDC(PHandle);
  1444.   pData := nil;
  1445.   HBitMap := CreateDIBSection(0, A_FOutInfo, DIB_RGB_COLORS, pData, 0, 0);
  1446.   if not Assigned(pData) and (HBitMap = 0) then
  1447.   begin
  1448.     Abort;
  1449.   end;
  1450.   pData := Buf;
  1451.   SetImage(HBitMap);
  1452.   GdiFlush;
  1453.   MemDC := CreateCompatibleDC(pDC);
  1454.   SelectObject(MemDC, HBitMap);
  1455.   BitBlt(pDC, 0, 0, A_FOutInfo.bmiHeader.biWidth, A_FOutInfo.bmiHeader.biHeight,
  1456.     MemDC, 0, 0, SRCCOPY);
  1457.   DeleteDC(MemDC);
  1458. end;
  1459. {------------------------------------------------------------------------------}
  1460. {注销}
  1461. procedure TRealMessengerX.MDisconnectClick(Sender: TObject);
  1462. begin
  1463.   ClientLogout();
  1464. end;
  1465. {------------------------------------------------------------------------------}
  1466. procedure TRealMessengerX.ApplicationEvents1Exception(Sender: TObject;
  1467.   E: Exception);
  1468. begin
  1469.   //ShowMessage(E.Message);
  1470. end;
  1471. {------------------------------------------------------------------------------}
  1472. procedure TRealMessengerX.LblMyStateClick(Sender: TObject);
  1473. var
  1474.   Point: TPoint;
  1475. begin
  1476.   if Me = nil then exit;
  1477.   if AnsiSameText(Me.State, '断开') then exit;
  1478.   Point.X := 0;
  1479.   Point.Y := LblMyState.Height;
  1480.   PpMenuStates.Popup(LblMyState.ClientToScreen(Point).X - 18, LblMyState.ClientToScreen(Point).Y + 2);
  1481. end;
  1482. {------------------------------------------------------------------------------}
  1483. procedure TRealMessengerX.HartTimerTimer(Sender: TObject);
  1484. begin
  1485.   if ClientTCP.Connected = False then exit;
  1486.   try
  1487.     ClientTCP.WriteBuffer(skOnlineCheck, 1, True);
  1488.   except
  1489.     ClientLogout();
  1490.   end;
  1491.   if GetTickCount - LastReturnHartTick > HartTimer.Interval * 5 then
  1492.   begin
  1493.     ClientLogout();
  1494.   end;
  1495. end;
  1496. {------------------------------------------------------------------------------}
  1497. procedure TRealMessengerX.TrevUserListMouseDown(Sender: TObject;
  1498.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  1499. var
  1500.   TreeNode: TTreeNode;
  1501.   Point: TPoint;
  1502. begin
  1503.   TreeNode := TrevUserList.GetNodeAt(X, Y);
  1504.   if TreeNode = nil then
  1505.   begin
  1506.     exit;
  1507.   end
  1508.   else
  1509.   begin
  1510.     TreeNode.Selected := False;
  1511.     TreeNode.Selected := True;
  1512.   end;
  1513.   if (Button = mbRight) then
  1514.   begin
  1515.     Point.X := X;
  1516.     Point.Y := Y;
  1517.     if (TreeNode.StateIndex = 2) then PpMenuRight.Popup(TrevUserList.ClientToScreen(Point).X, TrevUserList.ClientToScreen(Point).Y);
  1518.   end;
  1519. end;
  1520. {------------------------------------------------------------------------------}
  1521. procedure TRealMessengerX.TrevUserListChange(Sender: TObject;
  1522.   Node: TTreeNode);
  1523. begin
  1524.   MSendMsg.Enabled := False;
  1525.   MSendFile.Enabled := False;
  1526.   MSendVoice.Enabled := False;
  1527.   MSendVideo.Enabled := False;
  1528.   MShowHistory.Enabled := False;
  1529.   NR1.Enabled := False;
  1530.   NR2.Enabled := False;
  1531.   NR3.Enabled := False;
  1532.   NR4.Enabled := False;
  1533.   NR5.Enabled := False;
  1534.   NSplitOfGroup.Visible := True;
  1535.   NNewGroup.Visible := True;
  1536.   NDelGroup.Visible := True;
  1537.   NAddGroupMember.Visible := True;
  1538.   NRemoveFromGroup.Visible := True;
  1539.   if Node = nil then
  1540.   begin
  1541.     exit;
  1542.   end;
  1543.   if (Node.StateIndex = 2) then
  1544.   begin
  1545.     MSendMsg.Enabled := True;
  1546.     MSendFile.Enabled := True;
  1547.     MSendVoice.Enabled := True;
  1548.     MSendVideo.Enabled := True;
  1549.     MShowHistory.Enabled := True;
  1550.     NR1.Enabled := True;
  1551.     NR2.Enabled := True;
  1552.     NR3.Enabled := True;
  1553.     NR4.Enabled := True;
  1554.     NR5.Enabled := True;
  1555.   end;
  1556. end;
  1557. {------------------------------------------------------------------------------}
  1558. procedure TRealMessengerX.MAutoLeaveClick(Sender: TObject);
  1559. var
  1560.   TempReg: TRegistry;
  1561. begin
  1562.   TempReg := TRegistry.Create;
  1563.   try
  1564.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1565.     if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then
  1566.       if MAutoLeave.Checked then
  1567.       begin
  1568.         TempReg.WriteString('AutoLeave', '1');
  1569.         if STimer.Enabled = False then
  1570.         begin
  1571.           STimer.Enabled := True;
  1572.           Snoop := 0;
  1573.         end;
  1574.       end
  1575.       else
  1576.         TempReg.WriteString('AutoLeave', '0')
  1577.   finally
  1578.     TempReg.Free;
  1579.   end;
  1580. end;
  1581. {------------------------------------------------------------------------------}
  1582. procedure TRealMessengerX.MAutoBusyClick(Sender: TObject);
  1583. var
  1584.   TempReg: TRegistry;
  1585. begin
  1586.   TempReg := TRegistry.Create;
  1587.   try
  1588.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1589.     if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then
  1590.       if MAutoLeave.Checked then
  1591.       begin
  1592.         TempReg.WriteString('AutoBusy', '1');
  1593.         if STimer.Enabled = False then
  1594.         begin
  1595.           STimer.Enabled := True;
  1596.           Snoop := 0;
  1597.         end;
  1598.       end
  1599.       else
  1600.         TempReg.WriteString('AutoBusy', '0')
  1601.   finally
  1602.     TempReg.Free;
  1603.   end;
  1604. end;
  1605. {------------------------------------------------------------------------------}
  1606. procedure TRealMessengerX.TrevUserListDblClick(Sender: TObject);
  1607. var
  1608.   ChatingForm: TChatingForm;
  1609.   Room: ChatRoom;
  1610. begin
  1611.   if TrevUserList.Selected.StateIndex <> 2 then exit;
  1612.   if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
  1613.   begin
  1614.     MessageBox(Handle, '不能与您自己对话!', '提示', MB_ICONINFORMATION);
  1615.     exit;
  1616.   end;
  1617.   Room.UserCount := 2;
  1618.   Room.Users[1] := Me.ID;
  1619.   Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
  1620.   ChatingForm := OpenChatingForm(Room);
  1621.   MsgAlertQueue.Remove(ChatingForm);
  1622.   if MsgAlertQueue.Count = 0 then
  1623.   begin
  1624.     CoolTrayIcon.CycleIcons := False;
  1625.     CoolTrayIcon.IconList := nil;
  1626.     ChangeLblMyStateCaption();
  1627.   end;
  1628.   ChatingForm.Pushed := True;
  1629.   ChatingForm.Show;
  1630.   ShowWindow(ChatingForm.Handle, SW_SHOW);
  1631.   if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
  1632.   if ChatingForm.CanFocus then ChatingForm.SetFocus;
  1633. end;
  1634. {------------------------------------------------------------------------------}
  1635. procedure TRealMessengerX.NR2Click(Sender: TObject);
  1636. var
  1637.   ChatingForm: TChatingForm;
  1638.   Room: ChatRoom;
  1639. begin
  1640.   if TrevUserList.Selected.StateIndex <> 2 then exit;
  1641.   if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
  1642.   begin
  1643.     MessageBox(Handle, '不能给您自己发送文件!', '提示', MB_ICONINFORMATION);
  1644.     exit;
  1645.   end;
  1646.   Room.UserCount := 2;
  1647.   Room.Users[1] := Me.ID;
  1648.   Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
  1649.   ChatingForm := OpenChatingForm(Room);
  1650.   ChatingForm.Show;
  1651.   if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
  1652.   if ChatingForm.CanFocus then ChatingForm.SetFocus;
  1653.   ChatingForm.ImgSendFileClick(nil);
  1654. end;
  1655. {------------------------------------------------------------------------------}
  1656. procedure TRealMessengerX.NR3Click(Sender: TObject);
  1657. var
  1658.   ChatingForm: TChatingForm;
  1659.   Room: ChatRoom;
  1660. begin
  1661.   if TrevUserList.Selected.StateIndex <> 2 then exit;
  1662.   if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
  1663.   begin
  1664.     MessageBox(Handle, '不能与您自己进行音频对话!', '提示', MB_ICONINFORMATION);
  1665.     exit;
  1666.   end;
  1667.   Room.UserCount := 2;
  1668.   Room.Users[1] := Me.ID;
  1669.   Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
  1670.   ChatingForm := OpenChatingForm(Room);
  1671.   ChatingForm.Show;
  1672.   if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
  1673.   if ChatingForm.CanFocus then ChatingForm.SetFocus;
  1674.   ChatingForm.ImgVoiceClick(nil);
  1675. end;
  1676. {------------------------------------------------------------------------------}
  1677. procedure TRealMessengerX.NR4Click(Sender: TObject);
  1678. var
  1679.   ChatingForm: TChatingForm;
  1680.   Room: ChatRoom;
  1681. begin
  1682.   if TrevUserList.Selected.StateIndex <> 2 then exit;
  1683.   if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
  1684.   begin
  1685.     MessageBox(Handle, '不能与您自己进行视频对话!', '提示', MB_ICONINFORMATION);
  1686.     exit;
  1687.   end;
  1688.   Room.UserCount := 2;
  1689.   Room.Users[1] := Me.ID;
  1690.   Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
  1691.   ChatingForm := OpenChatingForm(Room);
  1692.   ChatingForm.Show;
  1693.   if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
  1694.   if ChatingForm.CanFocus then ChatingForm.SetFocus;
  1695.   ChatingForm.ImgVideoClick(nil);
  1696. end;
  1697. {------------------------------------------------------------------------------}
  1698. procedure TRealMessengerX.CoolTrayIconDblClick(Sender: TObject);
  1699. var
  1700.   ChatingForm: TChatingForm;
  1701. begin
  1702.   try
  1703.     if MsgAlertQueue.Count > 0 then
  1704.     begin
  1705.       ChatingForm := MsgAlertQueue.Items[0];
  1706.       MsgAlertQueue.Remove(ChatingForm);
  1707.       if ChatingForm <> nil then
  1708.       begin
  1709.         ChatingForm.Show;
  1710.         ShowWindow(ChatingForm.Handle, SW_SHOW);
  1711.         if ChatingForm.WindowState = wsMinimized then ChatingForm.WindowState := wsNormal;
  1712.         SetForegroundWindow(ChatingForm.Handle);
  1713.       end;
  1714.       if MsgAlertQueue.Count = 0 then
  1715.       begin
  1716.         CoolTrayIcon.CycleIcons := False;
  1717.         CoolTrayIcon.IconList := nil;
  1718.         ChangeLblMyStateCaption();
  1719.       end;
  1720.     end
  1721.     else
  1722.     begin
  1723.       try
  1724.         ShowWindow(Handle, SW_SHOW);
  1725.         RealMessengerX.CoolTrayIcon.ShowTaskbarIcon;
  1726.         jfForceForeGroundWindow(Handle);
  1727.       finally
  1728.         MOpen.Visible := False;
  1729.       end;
  1730.     end;
  1731.   except
  1732.   end;
  1733. end;
  1734. {------------------------------------------------------------------------------}
  1735. procedure TRealMessengerX.NR5Click(Sender: TObject);
  1736. begin
  1737.   if TrevUserList.Selected.StateIndex <> 2 then exit;
  1738.   if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
  1739.   begin
  1740.     MessageBox(Handle, '不存在与您自己的对话记录!', '提示', MB_ICONINFORMATION);
  1741.     exit;
  1742.   end;
  1743.   if HistoryForm <> nil then HistoryForm.Close;
  1744.   HistoryForm := THistoryForm.Create(Application);
  1745.   HistoryForm.ID := PEmployee(TrevUserList.Selected.Data).ID;
  1746.   HistoryForm.Name := PEmployee(TrevUserList.Selected.Data).Name;
  1747.   HistoryForm.Show;
  1748. end;
  1749. {------------------------------------------------------------------------------}
  1750. procedure TRealMessengerX.TrevUserListMouseMove(Sender: TObject;
  1751.   Shift: TShiftState; X, Y: Integer);
  1752. var
  1753.   Node: TTreeNode;
  1754.   P: TPoint;
  1755. begin
  1756.   Node := TrevUserList.GetNodeAt(X, Y);
  1757.   if Node = nil then
  1758.   begin
  1759.     Application.CancelHint;
  1760.     exit;
  1761.   end;
  1762.   if (Node.StateIndex <> 1) and (Node.StateIndex <> 2) then
  1763.   begin
  1764.     Application.CancelHint;
  1765.     exit;
  1766.   end;
  1767.   if Node = CurNode then
  1768.   begin
  1769.     exit;
  1770.   end;
  1771.   P.X := Node.DisplayRect(True).Left + TrevUserList.Canvas.TextWidth(Node.Text) + 5;
  1772.   P.Y := Node.DisplayRect(True).top + PnlRoot.top;
  1773.   if Node.StateIndex = 2 then
  1774.   begin
  1775.     TrevUserList.Hint := Node.Text + #13 + PEmployee(Node.Data)^.ToolTips
  1776.   end
  1777.   else
  1778.   begin
  1779.     Application.CancelHint;
  1780.   end;
  1781.   Application.ActivateHint(Point(ClientToScreen(P).X, ClientToScreen(P).Y));
  1782.   CurNode := Node;
  1783. end;
  1784. {------------------------------------------------------------------------------}
  1785. procedure TRealMessengerX.STimerTimer(Sender: TObject);
  1786. var
  1787.   Rct: TRect;
  1788.   Point: TPoint;
  1789.   Text: array[0..255] of char;
  1790. begin
  1791.   if TrevUserList.Visible = False then exit;
  1792.   try
  1793.     Snoop := Snoop + STimer.Interval;
  1794.     GetCursorPos(Point);
  1795.     if (OldMousePoint.X <> Point.X) or (OldMousePoint.Y <> Point.Y) then
  1796.     begin
  1797.       Snoop := 0;
  1798.       OldMousePoint.X := Point.X;
  1799.       OldMousePoint.Y := Point.Y;
  1800.     end;
  1801.     if (Snoop > 300000) and MAutoLeave.Checked then //5 分钟之内没有动作
  1802.     begin
  1803.       if AnsiSameText(Me.State, '联机') then
  1804.       begin
  1805.         ChangeMyState('离开', True);
  1806.       end;
  1807.     end
  1808.     else if IsAutoState and AnsiSameText(Me.State, '离开') then
  1809.     begin
  1810.       ChangeMyState('联机');
  1811.     end;
  1812.     GetClassName(GetForegroundWindow, @Text, 256);
  1813.     if (not AnsiSameText(StrPas(Text), 'WorkerW')) and (not AnsiSameText(StrPas(Text), 'Progman')) then
  1814.     begin
  1815.       GetWindowRect(GetForegroundWindow, Rct);
  1816.       IntersectRect(Rct, Rct, Screen.DesktopRect);
  1817.       if EqualRect(Rct, Screen.DesktopRect) then //正在运行全屏程序
  1818.       begin
  1819.         if AnsiSameText(Me.State, '联机') and (MAutoBusy.Checked) and (CopyScreenForm = nil) then
  1820.         begin
  1821.           ChangeMyState('忙碌', True);
  1822.           exit;
  1823.         end;
  1824.       end
  1825.       else if IsAutoState and AnsiSameText(Me.State, '忙碌') then
  1826.       begin
  1827.         ChangeMyState('联机');
  1828.         exit;
  1829.       end;
  1830.     end;
  1831.   except
  1832.   end;
  1833.   {检测是否有新邮件}
  1834.   try
  1835.     if (LastMailCount <> -1) and (CurrentMailCount > LastMailCount) then
  1836.     begin
  1837.       ShowAlert('系统信息', '您收到 ' + IntToStr((CurrentMailCount - LastMailCount)) + ' 封新邮件', True);
  1838.       LastMailCount := CurrentMailCount;
  1839.     end;
  1840.   except
  1841.   end;
  1842. end;
  1843. {------------------------------------------------------------------------------}
  1844. procedure TRealMessengerX.ActiveFormDestroy(Sender: TObject);
  1845. var
  1846.   TempReg: TRegistry;
  1847. begin
  1848.   TempReg := TRegistry.Create;
  1849.   try
  1850.     STimer.Enabled := False;
  1851.     HartTimer.Enabled := False;
  1852.     TimerAutoConnect.Enabled := False;
  1853.     HartTimer.Enabled := False;
  1854.     MySockets.Free;
  1855.     ReceivedMessages.Free;
  1856.     MsgReturnCheck.Free;
  1857.     Branchs.Free;
  1858.     Employees.Free;
  1859.     TransmitFiles.Free;
  1860.     AudioHandShakes.Free;
  1861.     VideoHandShakes.Free;
  1862.     MsgAlertQueue.Free;
  1863.     MsgFormList.Free;
  1864.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1865.     if TempReg.OpenKey(AppKey + 'FormStore', True) then
  1866.     begin
  1867.       TempReg.WriteString('Left', IntToStr(Left));
  1868.       TempReg.WriteString('Top', IntToStr(top));
  1869.       TempReg.WriteString('Width', IntToStr(Width));
  1870.       TempReg.WriteString('Height', IntToStr(Height));
  1871.     end;
  1872.   finally
  1873.     TempReg.Free;
  1874.   end;
  1875. end;
  1876. {------------------------------------------------------------------------------}
  1877. procedure TRealMessengerX.FormClose(Sender: TObject;
  1878.   var Action: TCloseAction);
  1879. begin
  1880.   Action := caNone;
  1881.   ZoomEffect(Self, zaMinimize);
  1882.   ShowWindow(RealMessengerX.Handle, SW_HIDE);
  1883.   RealMessengerX.CoolTrayIcon.HideTaskbarIcon;
  1884.   MOpen.Visible := True;
  1885. end;
  1886. {------------------------------------------------------------------------------}
  1887. procedure TRealMessengerX.MExitClick(Sender: TObject);
  1888. begin
  1889.   try
  1890.     if MDisconnect.Enabled then MDisconnectClick(nil);
  1891.     Refresh;
  1892.     Sleep(500);
  1893.     Close;
  1894.     Release;
  1895.   finally
  1896.     Application.Terminate;
  1897.   end;
  1898. end;
  1899. {------------------------------------------------------------------------------}
  1900. procedure TRealMessengerX.FormShow(Sender: TObject);
  1901. begin
  1902.   ChangeAllColor(EndColor);
  1903.   OnShow := nil;
  1904. end;
  1905. {------------------------------------------------------------------------------}
  1906. procedure TRealMessengerX.TimerAutoConnectTimer(Sender: TObject);
  1907. begin
  1908. showmessage('1');
  1909.   if (not TrevUserList.Visible) and (not DontAutoConnect) and (HostName <> '') and (ServerPort > 0) and (LoginName <> '') and (Password <> '') then
  1910.   begin
  1911.     SendIdentity();
  1912.   end;
  1913. end;
  1914. {------------------------------------------------------------------------------}
  1915. procedure TRealMessengerX.NNewGroupClick(Sender: TObject);
  1916. var
  1917.   TempReg: TRegistry;
  1918.   GroupName: string;
  1919. begin
  1920.   GroupName := trim(ShowMyInputBox('输入', '请输入您要新建的组名称:', '', 30));
  1921.   if trim(GroupName) = '' then exit;
  1922.   TempReg := TRegistry.Create;
  1923.   try
  1924.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1925.     if TempReg.KeyExists(AppKey + '' + LoginName + 'Group' + trim(GroupName)) then
  1926.     begin
  1927.       MessageBox(Handle, '指定的组已存在!', '提示', MB_ICONINFORMATION);
  1928.       exit;
  1929.     end
  1930.     else
  1931.     begin
  1932.       TempReg.CreateKey(AppKey + '' + LoginName + 'Group' + trim(GroupName));
  1933.       TrevUserList.Items.AddChild(nil, trim(GroupName)).SelectedIndex := -1; {-1表示自定义组方式}
  1934.     end;
  1935.   finally
  1936.     TempReg.Free;
  1937.   end;
  1938. end;
  1939. {------------------------------------------------------------------------------}
  1940. procedure TRealMessengerX.NDelGroupClick(Sender: TObject);
  1941. var
  1942.   TempReg: TRegistry;
  1943.   GroupName: string;
  1944.   Node: TTreeNode;
  1945. begin
  1946.   Node := TrevUserList.Selected;
  1947.   if Node.StateIndex = 2 then Node := Node.Parent;
  1948.   GroupName := Node.Text;
  1949.   TempReg := TRegistry.Create;
  1950.   try
  1951.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1952.     TempReg.DeleteKey(AppKey + '' + LoginName + 'Group' + trim(GroupName));
  1953.     Node.Delete;
  1954.   finally
  1955.     TempReg.Free;
  1956.   end;
  1957. end;
  1958. {------------------------------------------------------------------------------}
  1959. procedure TRealMessengerX.NRemoveFromGroupClick(Sender: TObject);
  1960. var
  1961.   TempReg: TRegistry;
  1962.   GroupName: string;
  1963.   Employee: PEmployee;
  1964.   Node: TTreeNode;
  1965. begin
  1966.   Node := TrevUserList.Selected.Parent;
  1967.   GroupName := Node.Text;
  1968.   Employee := PEmployee(TrevUserList.Selected.Data);
  1969.   TempReg := TRegistry.Create;
  1970.   try
  1971.     TempReg.RootKey := HKEY_LOCAL_MACHINE;
  1972.     if TempReg.OpenKey(AppKey + '' + LoginName + 'Group' + trim(GroupName), False) then
  1973.     begin
  1974.       TempReg.DeleteValue(IntToStr(Employee.ID));
  1975.       TrevUserList.Selected.Delete;
  1976.       Employee.Node := nil;
  1977.     end;
  1978.   finally
  1979.     TempReg.Free;
  1980.   end;
  1981. end;
  1982. {------------------------------------------------------------------------------}
  1983. procedure TRealMessengerX.NAddGroupMemberClick(Sender: TObject);
  1984. var
  1985.   TempReg: TRegistry;
  1986.   iLoop, jLoop: Integer;
  1987.   Employee1, Employee2: PEmployee;
  1988.   GroupName: string;
  1989.   GroupNode: TTreeNode;
  1990. begin
  1991.   GroupNode := TrevUserList.Selected;
  1992.   if GroupNode.StateIndex = 2 then GroupNode := GroupNode.Parent;
  1993.   GroupName := GroupNode.Text;
  1994.   SelUserForm := TSelUserForm.Create(Self);
  1995.   try
  1996.     if SelUserForm.ShowModal = mrOK then
  1997.     begin
  1998.       for iLoop := 0 to SelUserForm.TrevUserList.Items.Count - 1 do
  1999.       begin
  2000.         if (SelUserForm.TrevUserList.Items[iLoop].ImageIndex < 6) or (SelUserForm.TrevUserList.Items[iLoop].ImageIndex > 13) then continue;
  2001.         if IsNodeChecked(SelUserForm.TrevUserList.Items[iLoop]) = False then continue;
  2002.         Employee1 := PEmployee(SelUserForm.TrevUserList.Items[iLoop].Data);
  2003.         for jLoop := TrevUserList.Items.Count - 1 downto 0 do
  2004.         begin
  2005.           if TrevUserList.Items[jLoop].StateIndex <> 2 then continue;
  2006.           Employee2 := PEmployee(TrevUserList.Items[jLoop].Data);
  2007.           if Employee1.ID = Employee2.ID then
  2008.           begin
  2009.             Employee2.Node.Selected := True;
  2010.             NRemoveFromGroupClick(nil);
  2011.           end;
  2012.         end;
  2013.         TempReg := TRegistry.Create;
  2014.         try
  2015.           TempReg.RootKey := HKEY_LOCAL_MACHINE;
  2016.           if TempReg.OpenKey(AppKey + '' + LoginName + 'Group' + trim(GroupName), False) then
  2017.           begin
  2018.             with Employees.LockList do
  2019.             try
  2020.               for jLoop := 0 to Count - 1 do
  2021.               begin
  2022.                 Employee2 := Items[jLoop];
  2023.                 if Employee1.ID = Employee2.ID then
  2024.                 begin
  2025.                   TempReg.WriteString(IntToStr(Employee2.ID), Employee2.LoginName);
  2026.                   Employee2.Node := TrevUserList.Items.AddChildObject(GroupNode, Employee2.Name, Employee2);
  2027.                   Employee2.Node.StateIndex := 2 {2表示为用户};
  2028.                   UpdateListViewStates(TrevUserList, Employee2.Node); {更新用户状态}
  2029.                   break;
  2030.                 end;
  2031.               end;
  2032.             finally
  2033.               Employees.UnlockList;
  2034.             end;
  2035.           end;
  2036.         finally
  2037.           TempReg.Free;
  2038.         end;
  2039.       end;
  2040.       GroupNode.Expanded := True;
  2041.     end;
  2042.   finally
  2043.     SelUserForm.Free;
  2044.     SelUserForm := nil;
  2045.   end;
  2046. end;
  2047. {------------------------------------------------------------------------------}
  2048. procedure TRealMessengerX.MConnectSetClick(Sender: TObject);
  2049. begin
  2050.   if SystemSetForm <> nil then exit;
  2051.   SystemSetForm := TSystemSetForm.Create(Self);
  2052.   SystemSetForm.ShowModal;
  2053.   SystemSetForm.Free;
  2054.   SystemSetForm := nil;
  2055. end;
  2056. {------------------------------------------------------------------------------}
  2057. procedure TRealMessengerX.MShowSysHistoryClick(Sender: TObject);
  2058. begin
  2059.   if HistoryForm <> nil then HistoryForm.Close;
  2060.   HistoryForm := THistoryForm.Create(Application);
  2061.   HistoryForm.ID := -1;
  2062.   HistoryForm.Name := '系统消息';
  2063.   HistoryForm.Show;
  2064. end;
  2065. {------------------------------------------------------------------------------}
  2066. procedure TRealMessengerX.LblFileClick(Sender: TObject);
  2067. var
  2068.   Point: TPoint;
  2069. begin
  2070.   Point.X := 0;
  2071.   Point.Y := LblFile.Height;
  2072.   PopFile.Popup(LblFile.ClientToScreen(Point).X - 4, LblFile.ClientToScreen(Point).Y + 2);
  2073. end;
  2074. {------------------------------------------------------------------------------}
  2075. procedure TRealMessengerX.ImgClosedClick(Sender: TObject);
  2076. begin
  2077.   if MessageBox(Handle, '确定要退出程序吗?', '确认退出', MB_ICONQUESTION or MB_OKCANCEL) = ID_OK then Self.MExitClick(nil);
  2078. end;
  2079. {------------------------------------------------------------------------------}
  2080. procedure TRealMessengerX.ImgMinMouseDown(Sender: TObject;
  2081.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2082. begin
  2083.   (Sender as TImage).Left := (Sender as TImage).Left + 1;
  2084.   (Sender as TImage).top := (Sender as TImage).top + 1;
  2085. end;
  2086. {------------------------------------------------------------------------------}
  2087. procedure TRealMessengerX.ImgMinMouseUp(Sender: TObject;
  2088.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2089. begin
  2090.   (Sender as TImage).Left := (Sender as TImage).Left - 1;
  2091.   (Sender as TImage).top := (Sender as TImage).top - 1;
  2092. end;
  2093. {------------------------------------------------------------------------------}
  2094. procedure TRealMessengerX.LblFileMouseMove(Sender: TObject;
  2095.   Shift: TShiftState; X, Y: Integer);
  2096. begin
  2097.   ImgIndex := (Sender as TLabel).Tag;
  2098.   if ImgIndex = LastImgIndex then exit;
  2099.   ImgDraw.Canvas.lock;
  2100.   with ImgDraw.Canvas do
  2101.   begin
  2102.     Pen.Mode := pmCopy;
  2103.     Pen.Style := psClear;
  2104.     Rectangle(0, 0, ImgDraw.Width + 1, ImgDraw.Height + 1);
  2105.     Pen.Style := psSolid;
  2106.     Pen.Color := $00FEFEFE;
  2107.     Pen.Width := 1;
  2108.     MoveTo((Sender as TLabel).Left - ImgDraw.Left - 4, 17);
  2109.     LineTo(PenPos.X, 0);
  2110.     LineTo(PenPos.X + (Sender as TLabel).Width + 4, 0);
  2111.     Pen.Color := EndColor;
  2112.     LineTo(PenPos.X, 17);
  2113.     LineTo(PenPos.X - (Sender as TLabel).Width - 4, 17);
  2114.     Pen.Mode := pmWhite;
  2115.     Pen.Style := psSolid;
  2116.     Refresh;
  2117.   end;
  2118.   LastImgIndex := ImgIndex;
  2119.   TimerTopBar.Enabled := True;
  2120.   ImgDraw.Canvas.Unlock;
  2121. end;
  2122. {------------------------------------------------------------------------------}
  2123. procedure TRealMessengerX.TimerTopBarTimer(Sender: TObject);
  2124. var
  2125.   P: TPoint;
  2126. begin
  2127.   GetCursorPos(P);
  2128.   if (P.X < Left + ImgDraw.Left) or
  2129.     (P.X > Left + ImgDraw.Left + ImgDraw.Width) or
  2130.     (P.Y < top + ImgDraw.top) or
  2131.     (P.Y > top + ImgDraw.top + ImgDraw.Height) then
  2132.   begin
  2133.     with ImgDraw.Canvas do
  2134.     begin
  2135.       Pen.Mode := pmCopy;
  2136.       Pen.Style := psClear;
  2137.       Rectangle(0, 0, ImgDraw.Width + 1, ImgDraw.Height + 1);
  2138.     end;
  2139.     ImgIndex := -1;
  2140.     LastImgIndex := -1;
  2141.     TimerTopBar.Enabled := False;
  2142.   end;
  2143. end;
  2144. {------------------------------------------------------------------------------}
  2145. procedure TRealMessengerX.LblFileMouseDown(Sender: TObject;
  2146.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2147. begin
  2148.   ImgDraw.Canvas.lock;
  2149.   with ImgDraw.Canvas do
  2150.   begin
  2151.     Pen.Mode := pmCopy;
  2152.     Pen.Style := psClear;
  2153.     Rectangle(0, 0, ImgDraw.Width + 1, ImgDraw.Height + 1);
  2154.     Pen.Style := psSolid;
  2155.     Pen.Color := EndColor;
  2156.     Pen.Width := 1;
  2157.     MoveTo((Sender as TLabel).Left - ImgDraw.Left - 4, 17);
  2158.     LineTo(PenPos.X, 0);
  2159.     LineTo(PenPos.X + (Sender as TLabel).Width + 4, 0);
  2160.     Pen.Color := $00FEFEFE;
  2161.     LineTo(PenPos.X, 17);
  2162.     LineTo(PenPos.X - (Sender as TLabel).Width - 4, 17);
  2163.     Pen.Mode := pmWhite;
  2164.     Pen.Style := psSolid;
  2165.     Refresh;
  2166.   end;
  2167.   TimerTopBar.Enabled := True;
  2168.   ImgDraw.Canvas.Unlock;
  2169. end;
  2170. {------------------------------------------------------------------------------}
  2171. procedure TRealMessengerX.ImgMinClick(Sender: TObject);
  2172. begin
  2173.   Close;
  2174. end;
  2175. {------------------------------------------------------------------------------}
  2176. procedure TRealMessengerX.ImgTitleMouseDown(Sender: TObject;
  2177.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2178. begin
  2179.   if (Button = mbLeft) then
  2180.   begin
  2181.     ReleaseCapture;
  2182.     Self.Perform(WM_SYSCOMMAND, $F012, 0);
  2183.   end;
  2184. end;
  2185. {------------------------------------------------------------------------------}
  2186. procedure TRealMessengerX.LblMailCountClick(Sender: TObject);
  2187. var
  2188.   ThreadId: DWORD;
  2189. begin
  2190.   Pop3ServerForm := TPop3ServerForm.Create(Self);
  2191.   try
  2192.     if Pop3ServerForm.ShowModal = mrOK then
  2193.     begin
  2194.       if CheckPOP3ThreadHandle <> 0 then TerminateThread(CheckPOP3ThreadHandle, 4);
  2195.       CheckPOP3ThreadHandle := CreateThread(nil, 0, @CheckPOP3Thread, nil, 0, ThreadId);
  2196.     end;
  2197.   finally
  2198.     Pop3ServerForm.Free;
  2199.   end;
  2200. end;
  2201. {------------------------------------------------------------------------------}
  2202. constructor TClientHandleThread.Create;
  2203. begin
  2204.   inherited Create(True);
  2205.   FLock := TCriticalSection.Create;
  2206.   Resume;
  2207. end;
  2208. {------------------------------------------------------------------------------}
  2209. destructor TClientHandleThread.Destroy;
  2210. begin
  2211.   inherited Destroy;
  2212.   FLock.Free;
  2213. end;
  2214. {------------------------------------------------------------------------------}
  2215. procedure TClientHandleThread.ProcessCBLoginResult;
  2216. begin
  2217.   if not CBLoginResult.IsLogin then
  2218.   begin
  2219.     RealMessengerX.ClientLogout;
  2220.     RealMessengerX.CoolTrayIcon.ShowBalloonHint('登录失败', CBLoginResult.Result, bitError, 15);
  2221.     if (not DontAutoConnect) and (string(CBLoginResult.Result) = ServerStopped) then
  2222.       RealMessengerX.TimerAutoConnect.Enabled := True
  2223.     else
  2224.       RealMessengerX.TimerAutoConnect.Enabled := False;
  2225.   end;
  2226. end;
  2227. {------------------------------------------------------------------------------}
  2228. procedure TClientHandleThread.ProcessCBSendBranch;
  2229. var
  2230.   PBranchData: PBranch;
  2231. begin
  2232.   if CBSendBranch.Current = 0 then Branchs.Clear;
  2233.   GetMem(PBranchData, SizeOf(Branch));
  2234.   CopyMemory(PBranchData, @(CBSendBranch.BranchData), SizeOf(Branch));
  2235.   PBranchData.Node := nil;
  2236.   Branchs.Add(PBranchData);
  2237.   RealMessengerX.TimerLoging.Enabled := False;
  2238.   RealMessengerX.TimerLoging.Enabled := True;
  2239.   RealMessengerX.LblLoging.Caption := '正在下载部门列表...';
  2240.   RealMessengerX.Gauge.MaxValue := CBSendBranch.Count;
  2241.   RealMessengerX.Gauge.Progress := CBSendBranch.Current;
  2242. end;
  2243. {------------------------------------------------------------------------------}
  2244. procedure TClientHandleThread.ProcessCBSendEmployee;
  2245. var
  2246.   PEmployeeData: PEmployee;
  2247. begin
  2248.   if CBSendEmployee.Current = 0 then Employees.Clear;
  2249.   GetMem(PEmployeeData, SizeOf(Employee));
  2250.   CopyMemory(PEmployeeData, @(CBSendEmployee.EmployeeData), SizeOf(Employee));
  2251.   PEmployeeData.Node := nil;
  2252.   PEmployeeData.MySocket := nil;
  2253.   Employees.Add(PEmployeeData);
  2254.   if PEmployeeData.LoginName = LoginName then Me := PEmployeeData;
  2255.   if CBSendEmployee.Current = CBSendEmployee.Count then
  2256.   begin
  2257.     RealMessengerX.ClientLogin;
  2258.   end
  2259.   else
  2260.   begin
  2261.     RealMessengerX.TimerLoging.Enabled := False;
  2262.     RealMessengerX.TimerLoging.Enabled := True;
  2263.     RealMessengerX.LblLoging.Caption := '正在下载帐号列表...';
  2264.     RealMessengerX.Gauge.MaxValue := CBSendEmployee.Count;
  2265.     RealMessengerX.Gauge.Progress := CBSendEmployee.Current;
  2266.   end;
  2267. end;
  2268. {------------------------------------------------------------------------------}
  2269. procedure TClientHandleThread.ProcessCBNameAndPasswordChanged;
  2270. var
  2271.   jLoop: Integer;
  2272.   PEmployeeData, Employee1: PEmployee;
  2273. begin
  2274.   PEmployeeData := FindEmployeeByID(CBNameAndPasswordChanged.ID);
  2275.   if PEmployeeData = nil then exit;
  2276.   PEmployeeData.Name := CBNameAndPasswordChanged.Name;
  2277.   RealMessengerX.UpdateListViewStates(RealMessengerX.TrevUserList, PEmployeeData.Node);
  2278.   if SelUserForm <> nil then
  2279.   begin
  2280.     for jLoop := 0 to SelUserForm.TrevUserList.Items.Count - 1 do
  2281.     begin
  2282.       if (SelUserForm.TrevUserList.Items[jLoop].ImageIndex < 6) or (SelUserForm.TrevUserList.Items[jLoop].ImageIndex > 13) then continue;
  2283.       Employee1 := PEmployee(SelUserForm.TrevUserList.Items[jLoop].Data);
  2284.       if Employee1.ID = PEmployeeData.ID then
  2285.       begin
  2286.         Employee1.State := PEmployeeData.State;
  2287.         RealMessengerX.UpdateListViewStates(SelUserForm.TrevUserList, Employee1.Node);
  2288.         break;
  2289.       end;
  2290.     end;
  2291.   end;
  2292.   if PEmployeeData.ID = Me.ID then
  2293.   begin
  2294.     IsAutoState := CBStateChanged.IsAutoState;
  2295.     RealMessengerX.UpdateMyState;
  2296.   end;
  2297.   for jLoop := 0 to ChatingFormList.Count - 1 do TChatingForm(ChatingFormList.Items[jLoop]).ShowTitle;
  2298. end;
  2299. {------------------------------------------------------------------------------}
  2300. procedure TClientHandleThread.ProcessCBStateChanged;
  2301. var
  2302.   iLoop, jLoop: Integer;
  2303.   PEmployeeData, Employee1: PEmployee;
  2304.   TransmitFile: TTransmitFile;
  2305.   AudioHandShake: TAudioHandShake;
  2306.   VideoHandShake: TVideoHandShake;
  2307. begin
  2308.   PEmployeeData := FindEmployeeByID(CBStateChanged.ID);
  2309.   if PEmployeeData = nil then exit;
  2310.   if AnsiSameText(CBStateChanged.State, '断开') then
  2311.   begin
  2312.     with TransmitFiles.LockList do
  2313.     try
  2314.       for jLoop := Count - 1 downto 0 do
  2315.       begin
  2316.         TransmitFile := Items[jLoop];
  2317.         if ((TransmitFile.SenderID = CBStateChanged.ID) or (TransmitFile.ReceiverID = CBStateChanged.ID)) and (TransmitFile.IsComleted = False) then TransmitFile.Logout;
  2318.       end;
  2319.     finally
  2320.       TransmitFiles.UnlockList;
  2321.     end;
  2322.     with AudioHandShakes.LockList do
  2323.     try
  2324.       for jLoop := Count - 1 downto 0 do
  2325.       begin
  2326.         AudioHandShake := Items[jLoop];
  2327.         if AudioHandShake.ID = CBStateChanged.ID then AudioHandShake.Logout;
  2328.       end;
  2329.     finally
  2330.       AudioHandShakes.UnlockList;
  2331.     end;
  2332.     with VideoHandShakes.LockList do
  2333.     try
  2334.       for jLoop := Count - 1 downto 0 do
  2335.       begin
  2336.         VideoHandShake := Items[jLoop];
  2337.         if VideoHandShake.ID = CBStateChanged.ID then VideoHandShake.Logout;
  2338.       end;
  2339.     finally
  2340.       VideoHandShakes.UnlockList;
  2341.     end;
  2342.     PEmployeeData.MySocket.Free;
  2343.     PEmployeeData.MySocket := nil;
  2344.   end;
  2345.   if (PEmployeeData.ID <> Me.ID) and (GetTickCount - ConnectedTicket > 10000) then
  2346.   begin
  2347.     if (AnsiSameText(CBStateChanged.State, '显示为脱机') or AnsiSameText(CBStateChanged.State, '断开')) and (not AnsiSameText(PEmployeeData.State, '显示为脱机') and not AnsiSameText(PEmployeeData.State, '断开')) then
  2348.     begin
  2349.       PlayEventSound(SoundPath + 'out.wav');
  2350.       ShowAlert('系统信息', PEmployeeData.Name + ' 刚刚离线', True); ;
  2351.     end;
  2352.     if (AnsiSameText(PEmployeeData.State, '显示为脱机') or AnsiSameText(PEmployeeData.State, '断开')) and (not AnsiSameText(CBStateChanged.State, '显示为脱机') and not AnsiSameText(CBStateChanged.State, '断开')) then
  2353.     begin
  2354.       PlayEventSound(SoundPath + 'in.wav');
  2355.       ShowAlert('系统信息', PEmployeeData.Name + ' 刚刚上线', True); ;
  2356.     end;
  2357.   end;
  2358.   PEmployeeData.State := CBStateChanged.State;
  2359.   PEmployeeData.HaveAudioDevice := CBStateChanged.HaveAudioDevice;
  2360.   PEmployeeData.HaveVideoDevice := CBStateChanged.HaveVideoDevice;
  2361.   RealMessengerX.UpdateListViewStates(RealMessengerX.TrevUserList, PEmployeeData.Node); //更新用户状态
  2362.   if SelUserForm <> nil then
  2363.   begin
  2364.     for jLoop := 0 to SelUserForm.TrevUserList.Items.Count - 1 do
  2365.     begin
  2366.       if (SelUserForm.TrevUserList.Items[jLoop].ImageIndex < 6) or (SelUserForm.TrevUserList.Items[jLoop].ImageIndex > 13) then continue;
  2367.       Employee1 := PEmployee(SelUserForm.TrevUserList.Items[jLoop].Data);
  2368.       if Employee1.ID = PEmployeeData.ID then
  2369.       begin
  2370.         Employee1.State := PEmployeeData.State;
  2371.         RealMessengerX.UpdateListViewStates(SelUserForm.TrevUserList, Employee1.Node); //更新用户状态
  2372.         break;
  2373.       end;
  2374.     end;
  2375.   end;
  2376.   if PEmployeeData.ID = Me.ID then
  2377.   begin
  2378.     IsAutoState := CBStateChanged.IsAutoState;
  2379.     RealMessengerX.UpdateMyState;
  2380.   end;
  2381.   for jLoop := 0 to ChatingFormList.Count - 1 do TChatingForm(ChatingFormList.Items[jLoop]).ShowTitle;
  2382. end;
  2383. {------------------------------------------------------------------------------}
  2384. procedure TClientHandleThread.ProcessCBBeginTalk;
  2385. var
  2386.   PEmployeeData: PEmployee;
  2387. begin
  2388.   PEmployeeData := FindEmployeeByID(CBBeginTalk.Sender);
  2389.   if PEmployeeData = nil then exit;
  2390.   if PEmployeeData.MySocket = nil then
  2391.   begin
  2392.     PEmployeeData.MySocket := TMySocket.Create(PEmployeeData.ID, RealMessengerX.ClientTCP, True);
  2393.   end;
  2394.   PEmployeeData.MySocket.ReceiverLocalIP := CBBeginTalk.LocalIP;
  2395.   PEmployeeData.MySocket.ReceiverLocalPort := CBBeginTalk.LocalPort;
  2396.   PEmployeeData.MySocket.ReceiverIP := CBBeginTalk.IP;
  2397.   PEmployeeData.MySocket.ReceiverPort := CBBeginTalk.Port;
  2398.   PEmployeeData.MySocket.BeginGetHole;
  2399. end;
  2400. {------------------------------------------------------------------------------}
  2401. procedure TClientHandleThread.ProcessCBPleaseUseTCP;
  2402. var
  2403.   AudioHandShake: TAudioHandShake;
  2404.   VideoHandShake: TVideoHandShake;
  2405.   iLoop: Integer;
  2406.   ChatingForm: TChatingForm;
  2407. begin
  2408.   if CBPleaseUseTCP.ForAudioAudio then
  2409.   begin
  2410.     with AudioHandShakes.LockList do
  2411.     try
  2412.       for iLoop := Count - 1 downto 0 do
  2413.       begin
  2414.         AudioHandShake := Items[iLoop];
  2415.         if AudioHandShake.IsAccepted and (AudioHandShake.ID = CBPleaseUseTCP.Sender) then
  2416.         begin
  2417.           ChatingForm := AudioHandShake.ChatingForm;
  2418.           if not ChatingForm.ImgMicDisabled.Visible then AudioHandShake.MySocket.MySocketCategory := scTCP;
  2419.         end;
  2420.       end;
  2421.     finally
  2422.       AudioHandShakes.UnlockList
  2423.     end;
  2424.   end
  2425.   else
  2426.   begin
  2427.     with VideoHandShakes.LockList do
  2428.     try
  2429.       for iLoop := Count - 1 downto 0 do
  2430.       begin
  2431.         VideoHandShake := Items[iLoop];
  2432.         if VideoHandShake.IsAccepted and (VideoHandShake.ID = CBPleaseUseTCP.Sender) then
  2433.         begin
  2434.           if CBPleaseUseTCP.ForVideoAudio then
  2435.           begin
  2436.             ChatingForm := VideoHandShake.ChatingForm;
  2437.             if not ChatingForm.ImgMicDisabled.Visible then VideoHandShake.AMySocket.MySocketCategory := scTCP;
  2438.           end
  2439.           else
  2440.           begin
  2441.             VideoHandShake.VMySocket.MySocketCategory := scTCP;
  2442.           end;
  2443.         end;
  2444.       end;
  2445.     finally
  2446.       VideoHandShakes.UnlockList
  2447.     end;
  2448.   end;
  2449. end;
  2450. {------------------------------------------------------------------------------}
  2451. procedure TClientHandleThread.ProcessCBInputing;
  2452. begin
  2453.   RealMessengerX.ProcessCBInputing(CBInputing);
  2454. end;
  2455. {------------------------------------------------------------------------------}
  2456. procedure TClientHandleThread.ProcessCBAddUser;
  2457. var
  2458.   iLoop: Integer;
  2459.   ChatingForm: TChatingForm;
  2460. begin
  2461.   ChatingForm := OpenChatingForm(CBAddUser.Room, False);
  2462.   if ChatingForm = nil then exit;
  2463.   for iLoop := 1 to CBAddUser.AddRoom.UserCount do
  2464.   begin
  2465.     ChatingForm.RoomInfo.UserCount := ChatingForm.RoomInfo.UserCount + 1;
  2466.     ChatingForm.RoomInfo.Users[ChatingForm.RoomInfo.UserCount] := CBAddUser.AddRoom.Users[iLoop];
  2467.   end;
  2468.   ChatingForm.ShowTitle;
  2469. end;
  2470. {------------------------------------------------------------------------------}
  2471. procedure TClientHandleThread.ProcessCBSendFileRequest;
  2472. var
  2473.   iLoop: Integer;
  2474.   ChatingForm: TChatingForm;
  2475.   PEmployeeData: PEmployee;
  2476. begin
  2477.   ChatingForm := OpenChatingForm(CBSendFileRequest.Room, True);
  2478.   if ChatingForm = nil then exit;
  2479.   PEmployeeData := FindEmployeeByID(CBSendFileRequest.Sender);
  2480.   if PEmployeeData = nil then exit;
  2481.   TTransmitFile.Create(tfGet, CBSendFileRequest.Sender, PEmployeeData.Name, Me.ID, Me.Name, CBSendFileRequest.FileName, ChatingForm, CBSendFileRequest.LocalIP, CBSendFileRequest.LocalPort, CBSendFileRequest.IP, CBSendFileRequest.Port, CBSendFileRequest.FileSize, CBSendFileRequest.FileID, CBSendFileRequest.BaseID, CBSendFileRequest.IsScreen);
  2482.   if not ChatingForm.Pushed then RealMessengerX.FlashTray(ChatingForm);
  2483. end;
  2484. {------------------------------------------------------------------------------}
  2485. procedure TClientHandleThread.ProcessCBSendFileResponse;
  2486. var
  2487.   TransmitFile: TTransmitFile;
  2488.   ChatingForm: TChatingForm;
  2489. begin
  2490.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileResponse.BaseID));
  2491.   if TransmitFile = nil then exit;
  2492.   TransmitFile.MySocket.ReceiverLocalIP := CBSendFileResponse.LocalIP;
  2493.   TransmitFile.MySocket.ReceiverLocalPort := CBSendFileResponse.LocalPort;
  2494.   TransmitFile.MySocket.ReceiverIP := CBSendFileResponse.IP;
  2495.   TransmitFile.MySocket.ReceiverPort := CBSendFileResponse.Port;
  2496.   TransmitFile.MySocket.BeginGetHole;
  2497.   ChatingForm := TransmitFile.ChatingForm;
  2498.   if ChatingForm = nil then exit;
  2499.   if CBSendFileResponse.IsAccept then
  2500.     TransmitFile.Accept
  2501.   else
  2502.   begin
  2503.     TransmitFile.Decline;
  2504.   end;
  2505. end;
  2506. {------------------------------------------------------------------------------}
  2507. procedure TClientHandleThread.ProcessCBSendFileResult;
  2508. begin
  2509.   RealMessengerX.ProcessCBSendFileResult(CBSendFileResult);
  2510. end;
  2511. {------------------------------------------------------------------------------}
  2512. procedure TClientHandleThread.ProcessCBSendFilePackage;
  2513. begin
  2514.   RealMessengerX.ProcessCBSendFilePackage(CBSendFilePackage);
  2515. end;
  2516. {------------------------------------------------------------------------------}
  2517. procedure TClientHandleThread.ProcessCBSendFileResume;
  2518. var
  2519.   iLoop: Integer;
  2520.   TransmitFile: TTransmitFile;
  2521.   E: IHTMLElement;
  2522. begin
  2523.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileResume.BaseID));
  2524.   if TransmitFile = nil then exit;
  2525.   E := (TransmitFile.ChatingForm.MsgContent.Document as IHTMLDocument2).all.item(TransmitFile.PercentID, 0) as IHTMLElement;
  2526.   E.innerHTML := '准备发送文件(正在接收断点续传信息)...';
  2527.   for iLoop := 0 to CBSendFileResume.BufferLength - 1 do
  2528.   begin
  2529.     PFileTableUnit(TransmitFile.FileTable.Items[CBSendFileResume.Start + iLoop]).IsAccepted := CBSendFileResume.ResumBuffer[iLoop + 1];
  2530.     if PFileTableUnit(TransmitFile.FileTable.Items[CBSendFileResume.Start + iLoop]).IsAccepted = '1' then TransmitFile.ResumedSize := TransmitFile.ResumedSize + FilePackSize;
  2531.   end;
  2532. end;
  2533. {------------------------------------------------------------------------------}
  2534. procedure TClientHandleThread.ProcessCBSendFileCompleted;
  2535. var
  2536.   TransmitFile: TTransmitFile;
  2537. begin
  2538.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileCompleted.BaseID));
  2539.   if TransmitFile = nil then exit;
  2540.   TransmitFile.IsComleted := True;
  2541.   TMoveFile.Create(TransmitFile);
  2542. end;
  2543. {------------------------------------------------------------------------------}
  2544. procedure TClientHandleThread.ProcessCBSendFileCancle;
  2545. var
  2546.   TransmitFile: TTransmitFile;
  2547.   ChatingForm: TChatingForm;
  2548. begin
  2549.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileCancle.BaseID));
  2550.   if TransmitFile = nil then exit;
  2551.   ChatingForm := TransmitFile.ChatingForm;
  2552.   if ChatingForm = nil then exit;
  2553.   TransmitFile.Cancel;
  2554. end;
  2555. {------------------------------------------------------------------------------}
  2556. procedure TClientHandleThread.ProcessCBSendFileStop;
  2557. var
  2558.   TransmitFile: TTransmitFile;
  2559.   ChatingForm: TChatingForm;
  2560. begin
  2561.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileStop.BaseID));
  2562.   if TransmitFile = nil then exit;
  2563.   ChatingForm := TransmitFile.ChatingForm;
  2564.   if ChatingForm = nil then exit;
  2565.   TransmitFile.Stop(CBSendFileStop.Sender);
  2566. end;
  2567. {------------------------------------------------------------------------------}
  2568. procedure TClientHandleThread.ProcessCBSetBitmapInfo;
  2569. begin
  2570.   FillChar(A_FInInfo, SizeOf(A_FInInfo), 0);
  2571.   Move(CBSetBitmapInfo.Buf, A_FInInfo, SizeOf(A_FInInfo));
  2572. end;
  2573. {------------------------------------------------------------------------------}
  2574. procedure TClientHandleThread.ProcessCBSetCompvars;
  2575. begin
  2576.   FillChar(A_FCV, SizeOf(A_FCV), 0);
  2577.   Move(CBSetCompvars.Buf, A_FCV, SizeOf(A_FCV));
  2578.   A_FCV.hic := ICOpen(A_FCV.fccType, A_FCV.fccHandler, ICMODE_DECOMPRESS);
  2579.   if A_FCV.hic = 0 then
  2580.   begin
  2581.     MessageBox(RealMessengerX.Handle, '您的机器未安装系统所需的MPEG4解码器!', '提示', MB_ICONINFORMATION);
  2582.   end else
  2583.   begin
  2584.     A_FOutFormatSize := ICDecompressGetFormatSize(A_FCV.hic, @A_FInInfo.bmiHeader);
  2585.     FillChar(A_FOutInfo, SizeOf(A_FOutInfo), 0);
  2586.     ICDecompressGetFormat(A_FCV.hic, @A_FInInfo, @A_FOutInfo);
  2587.     FOutBufSize := A_FOutInfo.bmiHeader.biSizeImage;
  2588.     if Assigned(FOutBuf) then FreeMem(FOutBuf);
  2589.     GetMem(FOutBuf, FOutBufSize);
  2590.     FillChar(FOutBuf^, FOutBufSize, 0);
  2591.     ICDecompressBegin(A_FCV.hic, @A_FInInfo, @A_FOutInfo);
  2592.   end;
  2593. end;
  2594. {------------------------------------------------------------------------------}
  2595. procedure TClientHandleThread.ProcessCBVideo;
  2596. begin
  2597.   RealMessengerX.ProcessCBVideo(CBVideo);
  2598. end;
  2599. {------------------------------------------------------------------------------}
  2600. procedure TClientHandleThread.ProcessCBMessage;
  2601. begin
  2602.   RealMessengerX.ProcessCBMessage(CBMessage);
  2603. end;
  2604. {------------------------------------------------------------------------------}
  2605. procedure TClientHandleThread.ProcessCBReturnMessage;
  2606. begin
  2607.   RealMessengerX.ProcessCBReturnMessage(CBReturnMessage);
  2608. end;
  2609. {------------------------------------------------------------------------------}
  2610. procedure TClientHandleThread.ProcessCBAudioRequest;
  2611. var
  2612.   ChatingForm: TChatingForm;
  2613.   PEmployeeData: PEmployee;
  2614. begin
  2615.   PEmployeeData := FindEmployeeByID(CBAudioRequest.Sender);
  2616.   if PEmployeeData = nil then exit;
  2617.   ChatingForm := OpenChatingForm(CBAudioRequest.Room, True);
  2618.   if ChatingForm = nil then exit;
  2619.   TAudioHandShake.Create(ahResponse, PEmployeeData.ID, PEmployeeData.Name, ChatingForm, CBAudioRequest.LocalIP, CBAudioRequest.LocalPort, CBAudioRequest.IP, CBAudioRequest.Port);
  2620.   if not ChatingForm.Pushed then RealMessengerX.FlashTray(ChatingForm);
  2621. end;
  2622. {------------------------------------------------------------------------------}
  2623. procedure TClientHandleThread.ProcessCBAudioResponse;
  2624. var
  2625.   ChatingForm: TChatingForm;
  2626.   AudioHandShake: TAudioHandShake;
  2627. begin
  2628.   AudioHandShake := FindAudioHandShakeByID(CBAudioResponse.Sender);
  2629.   if AudioHandShake = nil then exit;
  2630.   AudioHandShake.MySocket.ReceiverLocalIP := CBAudioResponse.LocalIP;
  2631.   AudioHandShake.MySocket.ReceiverLocalPort := CBAudioResponse.LocalPort;
  2632.   AudioHandShake.MySocket.ReceiverIP := CBAudioResponse.IP;
  2633.   AudioHandShake.MySocket.ReceiverPort := CBAudioResponse.Port;
  2634.   AudioHandShake.MySocket.BeginGetHole;
  2635.   ChatingForm := AudioHandShake.ChatingForm;
  2636.   if ChatingForm = nil then exit;
  2637.   if CBAudioResponse.isAcepted then
  2638.     AudioHandShake.Accept
  2639.   else
  2640.     AudioHandShake.Decline;
  2641. end;
  2642. {------------------------------------------------------------------------------}
  2643. procedure TClientHandleThread.ProcessCBAudioCancel;
  2644. var
  2645.   ChatingForm: TChatingForm;
  2646.   AudioHandShake: TAudioHandShake;
  2647. begin
  2648.   AudioHandShake := FindAudioHandShakeByID(CBAudioCancel.Sender);
  2649.   if AudioHandShake = nil then exit;
  2650.   ChatingForm := AudioHandShake.ChatingForm;
  2651.   if ChatingForm = nil then exit;
  2652.   AudioHandShake.Cancel;
  2653. end;
  2654. {------------------------------------------------------------------------------}
  2655. procedure TClientHandleThread.ProcessCBAudio;
  2656. begin
  2657.   RealMessengerX.ProcessCBAudio(CBAudio);
  2658. end;
  2659. {------------------------------------------------------------------------------}
  2660. procedure TClientHandleThread.ProcessCBAudioStop;
  2661. var
  2662.   ChatingForm: TChatingForm;
  2663.   AudioHandShake: TAudioHandShake;
  2664. begin
  2665.   AudioHandShake := FindAudioHandShakeByID(CBAudioStop.Sender);
  2666.   if AudioHandShake = nil then exit;
  2667.   ChatingForm := AudioHandShake.ChatingForm;
  2668.   if ChatingForm = nil then exit;
  2669.   AudioHandShake.Stop(CBAudioStop.Sender);
  2670. end;
  2671. {------------------------------------------------------------------------------}
  2672. procedure TClientHandleThread.ProcessCBVideoRequest;
  2673. var
  2674.   ChatingForm: TChatingForm;
  2675.   PEmployeeData: PEmployee;
  2676. begin
  2677.   PEmployeeData := FindEmployeeByID(CBVideoRequest.Sender);
  2678.   if PEmployeeData = nil then exit;
  2679.   ChatingForm := OpenChatingForm(CBVideoRequest.Room, True);
  2680.   if ChatingForm = nil then exit;
  2681.   TVideoHandShake.Create(vhResponse, PEmployeeData.ID, PEmployeeData.Name, ChatingForm,
  2682.     CBVideoRequest.ALocalIP, CBVideoRequest.ALocalPort, CBVideoRequest.AIP, CBVideoRequest.APort,
  2683.     CBVideoRequest.VLocalIP, CBVideoRequest.VLocalPort, CBVideoRequest.VIP, CBVideoRequest.VPort);
  2684.   if not ChatingForm.Pushed then RealMessengerX.FlashTray(ChatingForm);
  2685. end;
  2686. {------------------------------------------------------------------------------}
  2687. procedure TClientHandleThread.ProcessCBVideoResponse;
  2688. var
  2689.   ChatingForm: TChatingForm;
  2690.   VideoHandShake: TVideoHandShake;
  2691. begin
  2692.   VideoHandShake := FindVideoHandShakeByID(CBVideoResponse.Sender);
  2693.   if VideoHandShake = nil then exit;
  2694.   VideoHandShake.AMySocket.ReceiverLocalIP := CBVideoResponse.ALocalIP;
  2695.   VideoHandShake.AMySocket.ReceiverLocalPort := CBVideoResponse.ALocalPort;
  2696.   VideoHandShake.AMySocket.ReceiverIP := CBVideoResponse.AIP;
  2697.   VideoHandShake.AMySocket.ReceiverPort := CBVideoResponse.APort;
  2698.   VideoHandShake.AMySocket.BeginGetHole;
  2699.   VideoHandShake.VMySocket.ReceiverLocalIP := CBVideoResponse.VLocalIP;
  2700.   VideoHandShake.VMySocket.ReceiverLocalPort := CBVideoResponse.VLocalPort;
  2701.   VideoHandShake.VMySocket.ReceiverIP := CBVideoResponse.VIP;
  2702.   VideoHandShake.VMySocket.ReceiverPort := CBVideoResponse.VPort;
  2703.   VideoHandShake.VMySocket.BeginGetHole;
  2704.   ChatingForm := VideoHandShake.ChatingForm;
  2705.   if ChatingForm = nil then exit;
  2706.   if CBVideoResponse.isAcepted then
  2707.     VideoHandShake.Accept
  2708.   else
  2709.     VideoHandShake.Decline;
  2710. end;
  2711. {------------------------------------------------------------------------------}
  2712. procedure TClientHandleThread.ProcessCBVideoCancel;
  2713. var
  2714.   ChatingForm: TChatingForm;
  2715.   VideoHandShake: TVideoHandShake;
  2716. begin
  2717.   VideoHandShake := FindVideoHandShakeByID(CBVideoCancel.Sender);
  2718.   if VideoHandShake = nil then exit;
  2719.   ChatingForm := VideoHandShake.ChatingForm;
  2720.   if ChatingForm = nil then exit;
  2721.   VideoHandShake.Cancel;
  2722. end;
  2723. {------------------------------------------------------------------------------}
  2724. procedure TClientHandleThread.ProcessCBVideoStop;
  2725. var
  2726.   ChatingForm: TChatingForm;
  2727.   VideoHandShake: TVideoHandShake;
  2728. begin
  2729.   VideoHandShake := FindVideoHandShakeByID(CBVideoStop.Sender);
  2730.   if VideoHandShake = nil then exit;
  2731.   ChatingForm := VideoHandShake.ChatingForm;
  2732.   if ChatingForm = nil then exit;
  2733.   VideoHandShake.Stop(CBVideoStop.Sender);
  2734. end;
  2735. {------------------------------------------------------------------------------}
  2736. procedure TClientHandleThread.Execute;
  2737. var
  2738.   skType: char;
  2739. begin
  2740.   while not Terminated do
  2741.   begin
  2742.     if not RealMessengerX.ClientTCP.Connected then
  2743.       Terminate
  2744.     else
  2745.     try
  2746.       RealMessengerX.ClientTCP.ReadBuffer(skType, 1);
  2747.       {************************************************************************}
  2748.       if skType = skLoginResult then
  2749.       begin
  2750.         RealMessengerX.ClientTCP.ReadBuffer(CBLoginResult, SizeOf(CBLoginResult));
  2751.         Synchronize(ProcessCBLoginResult);
  2752.         continue;
  2753.       end;
  2754.       {************************************************************************}
  2755.       if skType = skSendBranch then
  2756.       begin
  2757.         RealMessengerX.ClientTCP.ReadBuffer(CBSendBranch, SizeOf(CBSendBranch));
  2758.         Synchronize(ProcessCBSendBranch);
  2759.         continue;
  2760.       end;
  2761.       {************************************************************************}
  2762.       if skType = skSendEmployee then
  2763.       begin
  2764.         RealMessengerX.ClientTCP.ReadBuffer(CBSendEmployee, SizeOf(CBSendEmployee));
  2765.         Synchronize(ProcessCBSendEmployee);
  2766.         continue;
  2767.       end;
  2768.       {************************************************************************}
  2769.       if skType = skStateChanged then
  2770.       begin
  2771.         RealMessengerX.ClientTCP.ReadBuffer(CBStateChanged, SizeOf(CBStateChanged));
  2772.         Synchronize(ProcessCBStateChanged);
  2773.         continue;
  2774.       end;
  2775.       {************************************************************************}
  2776.       if skType = skOnlineCheck then
  2777.       begin
  2778.         LastReturnHartTick := GetTickCount;
  2779.         continue;
  2780.       end;
  2781.       {************************************************************************}
  2782.       if skType = skBeginTalk then
  2783.       begin
  2784.         RealMessengerX.ClientTCP.ReadBuffer(CBBeginTalk, SizeOf(CBBeginTalk));
  2785.         Synchronize(ProcessCBBeginTalk);
  2786.         continue;
  2787.       end;
  2788.       {************************************************************************}
  2789.       if skType = skInputing then
  2790.       begin
  2791.         RealMessengerX.ClientTCP.ReadBuffer(CBInputing, SizeOf(CBInputing));
  2792.         Synchronize(ProcessCBInputing);
  2793.         continue;
  2794.       end;
  2795.       {************************************************************************}
  2796.       if skType = skMessage then
  2797.       begin
  2798.         RealMessengerX.ClientTCP.ReadBuffer(CBMessage, SizeOf(CBMessage));
  2799.         Synchronize(ProcessCBMessage);
  2800.         continue;
  2801.       end;
  2802.       {************************************************************************}
  2803.       if skType = skReturnMessage then
  2804.       begin
  2805.         RealMessengerX.ClientTCP.ReadBuffer(CBReturnMessage, SizeOf(CBReturnMessage));
  2806.         Synchronize(ProcessCBReturnMessage);
  2807.         continue;
  2808.       end;
  2809.       {************************************************************************}
  2810.       if skType = skAddUser then
  2811.       begin
  2812.         RealMessengerX.ClientTCP.ReadBuffer(CBAddUser, SizeOf(CBAddUser));
  2813.         Synchronize(ProcessCBAddUser);
  2814.         continue;
  2815.       end;
  2816.       {************************************************************************}
  2817.       if skType = skSendFileRequest then
  2818.       begin
  2819.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileRequest, SizeOf(CBSendFileRequest));
  2820.         Synchronize(ProcessCBSendFileRequest);
  2821.         continue;
  2822.       end;
  2823.       {************************************************************************}
  2824.       if skType = skSendFileCancle then
  2825.       begin
  2826.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileCancle, SizeOf(CBSendFileCancle));
  2827.         Synchronize(ProcessCBSendFileCancle);
  2828.         continue;
  2829.       end;
  2830.       {************************************************************************}
  2831.       if skType = skSendFileStop then
  2832.       begin
  2833.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileStop, SizeOf(CBSendFileStop));
  2834.         Synchronize(ProcessCBSendFileStop);
  2835.         continue;
  2836.       end;
  2837.       {************************************************************************}
  2838.       if skType = skSendFileResponse then
  2839.       begin
  2840.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileResponse, SizeOf(CBSendFileResponse));
  2841.         Synchronize(ProcessCBSendFileResponse);
  2842.         continue;
  2843.       end;
  2844.       {************************************************************************}
  2845.       if skType = skSendFilePackage then
  2846.       begin
  2847.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFilePackage, SizeOf(CBSendFilePackage));
  2848.         Synchronize(ProcessCBSendFilePackage);
  2849.         continue;
  2850.       end;
  2851.       {************************************************************************}
  2852.       if skType = skSendFileResult then
  2853.       begin
  2854.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileResult, SizeOf(CBSendFileResult));
  2855.         Synchronize(ProcessCBSendFileResult);
  2856.         continue;
  2857.       end;
  2858.       {************************************************************************}
  2859.       if skType = skSendFileResume then
  2860.       begin
  2861.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileResume, SizeOf(CBSendFileResume));
  2862.         Synchronize(ProcessCBSendFileResume);
  2863.         continue;
  2864.       end;
  2865.       {************************************************************************}
  2866.       if skType = skSendFileCompleted then
  2867.       begin
  2868.         RealMessengerX.ClientTCP.ReadBuffer(CBSendFileCompleted, SizeOf(CBSendFileCompleted));
  2869.         Synchronize(ProcessCBSendFileCompleted);
  2870.         continue;
  2871.       end;
  2872.       {************************************************************************}
  2873.       if skType = skAudioRequest then
  2874.       begin
  2875.         RealMessengerX.ClientTCP.ReadBuffer(CBAudioRequest, SizeOf(CBAudioRequest));
  2876.         Synchronize(ProcessCBAudioRequest);
  2877.         continue;
  2878.       end;
  2879.       {************************************************************************}
  2880.       if skType = skAudioResponse then
  2881.       begin
  2882.         RealMessengerX.ClientTCP.ReadBuffer(CBAudioResponse, SizeOf(CBAudioResponse));
  2883.         Synchronize(ProcessCBAudioResponse);
  2884.         continue;
  2885.       end;
  2886.       {************************************************************************}
  2887.       if skType = skAudioCancel then
  2888.       begin
  2889.         RealMessengerX.ClientTCP.ReadBuffer(CBAudioCancel, SizeOf(CBAudioCancel));
  2890.         Synchronize(ProcessCBAudioCancel);
  2891.         continue;
  2892.       end;
  2893.       {************************************************************************}
  2894.       if skType = skAudio then
  2895.       begin
  2896.         RealMessengerX.ClientTCP.ReadBuffer(CBAudio, SizeOf(CBAudio));
  2897.         Synchronize(ProcessCBAudio);
  2898.         continue;
  2899.       end;
  2900.       {************************************************************************}
  2901.       if skType = skAudioStop then
  2902.       begin
  2903.         RealMessengerX.ClientTCP.ReadBuffer(CBAudioStop, SizeOf(CBAudioStop));
  2904.         Synchronize(ProcessCBAudioStop);
  2905.         continue;
  2906.       end;
  2907.       {************************************************************************}
  2908.       if skType = skVideoRequest then
  2909.       begin
  2910.         RealMessengerX.ClientTCP.ReadBuffer(CBVideoRequest, SizeOf(CBVideoRequest));
  2911.         Synchronize(ProcessCBVideoRequest);
  2912.         continue;
  2913.       end;
  2914.       {************************************************************************}
  2915.       if skType = skVideoResponse then
  2916.       begin
  2917.         RealMessengerX.ClientTCP.ReadBuffer(CBVideoResponse, SizeOf(CBVideoResponse));
  2918.         Synchronize(ProcessCBVideoResponse);
  2919.         continue;
  2920.       end;
  2921.       {************************************************************************}
  2922.       if skType = skVideoCancel then
  2923.       begin
  2924.         RealMessengerX.ClientTCP.ReadBuffer(CBVideoCancel, SizeOf(CBVideoCancel));
  2925.         Synchronize(ProcessCBVideoCancel);
  2926.         continue;
  2927.       end;
  2928.       {************************************************************************}
  2929.       if skType = skVideoStop then
  2930.       begin
  2931.         RealMessengerX.ClientTCP.ReadBuffer(CBVideoStop, SizeOf(CBVideoStop));
  2932.         Synchronize(ProcessCBVideoStop);
  2933.         continue;
  2934.       end;
  2935.       {************************************************************************}
  2936.       if skType = skSetBitmapInfo then
  2937.       begin
  2938.         RealMessengerX.ClientTCP.ReadBuffer(CBSetBitmapInfo, SizeOf(CBSetBitmapInfo));
  2939.         Synchronize(ProcessCBSetBitmapInfo);
  2940.         continue;
  2941.       end;
  2942.       {************************************************************************}
  2943.       if skType = skSetCompvars then
  2944.       begin
  2945.         RealMessengerX.ClientTCP.ReadBuffer(CBSetCompvars, SizeOf(CBSetCompvars));
  2946.         Synchronize(ProcessCBSetCompvars);
  2947.         continue;
  2948.       end;
  2949.       {************************************************************************}
  2950.       if skType = skVideo then
  2951.       begin
  2952.         RealMessengerX.ClientTCP.ReadBuffer(CBVideo, SizeOf(CBVideo));
  2953.         Synchronize(ProcessCBVideo);
  2954.         continue;
  2955.       end;
  2956.       {************************************************************************}
  2957.       if skType = skPleaseUseTCP then
  2958.       begin
  2959.         RealMessengerX.ClientTCP.ReadBuffer(CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
  2960.         Synchronize(ProcessCBPleaseUseTCP);
  2961.         continue;
  2962.       end;
  2963.       {************************************************************************}
  2964.       if skType = skNameAndPasswordChanged then
  2965.       begin
  2966.         RealMessengerX.ClientTCP.ReadBuffer(CBNameAndPasswordChanged, SizeOf(CBNameAndPasswordChanged));
  2967.         Synchronize(ProcessCBNameAndPasswordChanged);
  2968.         continue;
  2969.       end;
  2970.     except
  2971.     end;
  2972.   end;
  2973. end;
  2974. {------------------------------------------------------------------------------}
  2975. procedure TRealMessengerX.ProcessCBVideo(CBVideo: TCBVideo);
  2976. var
  2977.   VideoHandShake: TVideoHandShake;
  2978.   ChatingForm: TChatingForm;
  2979.   RetVal, FPS, SPEED: Integer;
  2980.   SPEEDSTR: string;
  2981. begin
  2982.   VideoHandShake := FindVideoHandShakeByID(CBVideo.Sender);
  2983.   if VideoHandShake = nil then exit;
  2984.   VideoHandShake.VLastGetTicket := GetTickCount;
  2985.   ChatingForm := VideoHandShake.ChatingForm;
  2986.   if ChatingForm = nil then exit;
  2987.   if CBVideo.nSampleNum = 0 then
  2988.   begin
  2989.     VideoHandShake.StartTicket := GetTickCount;
  2990.     VideoHandShake.GetedData := 0;
  2991.     VideoHandShake.GetedFrame := 0;
  2992.   end;
  2993.   if (CBVideo.PackNO = 1) then
  2994.   begin
  2995.     FillChar(VideoHandShake.VideoData, SizeOf(TVideoDataInfo), 0);
  2996.     VideoHandShake.VideoData.bKeyFrame := CBVideo.bKeyFrame;
  2997.     VideoHandShake.VideoData.nSampleNum := CBVideo.nSampleNum;
  2998.     VideoHandShake.VideoData.nUsedSize := CBVideo.nAllSize;
  2999.     VideoHandShake.VideoData.nGetedSize := 0;
  3000.   end;
  3001.   if VideoHandShake.VideoData.nSampleNum <> CBVideo.nSampleNum then exit;
  3002.   if (VideoHandShake.VideoData.nGetedSize <> (CBVideo.PackNO - 1) * SizeOf(CBVideo.Buf)) then exit;
  3003.   CopyMemory(@(VideoHandShake.VideoData.Buf[VideoHandShake.VideoData.nGetedSize]), @(CBVideo.Buf[1]), CBVideo.BufLength);
  3004.   VideoHandShake.VideoData.nGetedSize := VideoHandShake.VideoData.nGetedSize + CBVideo.BufLength;
  3005.   if CBVideo.PackNO = CBVideo.PackCount then
  3006.   begin
  3007.     if (VideoHandShake.VideoData.nUsedSize > 0) and (VideoHandShake.VideoData.nUsedSize < 8180) then
  3008.     begin
  3009.       RetVal := ICDeCompress(A_FCV.hic, 0, @A_FInInfo.bmiHeader, @VideoHandShake.VideoData.Buf[0],
  3010.         @A_FOutInfo.bmiHeader, FOutBuf);
  3011.       if RetVal = ICERR_OK then
  3012.       begin
  3013.         try
  3014.           if VideoForm = nil then
  3015.           begin
  3016.             StretchDIBits(VideoHandShake.pDC,
  3017.               0, 0,
  3018.               160,
  3019.               120,
  3020.               0, 0,
  3021.               A_FOutInfo.bmiHeader.biWidth,
  3022.               A_FOutInfo.bmiHeader.biHeight,
  3023.               FOutBuf, A_FOutInfo, DIB_RGB_COLORS, SRCCOPY);
  3024.           end
  3025.           else
  3026.             StretchDIBits(VideoHandShake.pDC,
  3027.               0, 0,
  3028.               VideoForm.ClientWidth,
  3029.               VideoForm.ClientHeight,
  3030.               0, 0,
  3031.               A_FOutInfo.bmiHeader.biWidth,
  3032.               A_FOutInfo.bmiHeader.biHeight,
  3033.               FOutBuf, A_FOutInfo, DIB_RGB_COLORS, SRCCOPY)
  3034.         except
  3035.         end;
  3036.         VideoHandShake.GetedData := VideoHandShake.GetedData + SizeOf(CBVideo.Buf);
  3037.         VideoHandShake.GetedFrame := VideoHandShake.GetedFrame + 1;
  3038.         if GetTickCount - VideoHandShake.StartTicket > 1000 then
  3039.         begin
  3040.           FPS := VideoHandShake.GetedFrame * 1000 div (GetTickCount - VideoHandShake.StartTicket);
  3041.           SPEED := (VideoHandShake.GetedData * 1000 div (GetTickCount - VideoHandShake.StartTicket));
  3042.           if SPEED > 1024 then
  3043.             SPEEDSTR := IntToStr(SPEED div 1024) + 'K/S'
  3044.           else
  3045.             SPEEDSTR := '1K/S';
  3046.           if VideoForm = nil then
  3047.             ChatingForm.LblFPS.Caption := IntToStr(FPS) + 'FPS,' + SPEEDSTR
  3048.           else
  3049.             VideoForm.Caption := IntToStr(FPS) + 'FPS,' + SPEEDSTR;
  3050.           VideoHandShake.StartTicket := GetTickCount;
  3051.           VideoHandShake.GetedData := 0;
  3052.           VideoHandShake.GetedFrame := 0;
  3053.         end;
  3054.       end;
  3055.       FillChar(VideoHandShake.VideoData, SizeOf(TVideoDataInfo), 0);
  3056.     end;
  3057.   end;
  3058. end;
  3059. {------------------------------------------------------------------------------}
  3060. procedure TRealMessengerX.ProcessCBAudio(CBAudio: TCBAudio);
  3061. var
  3062.   ChatingForm: TChatingForm;
  3063.   AudioHandShake: TAudioHandShake;
  3064.   VideoHandShake: TVideoHandShake;
  3065. begin
  3066.   if not HaveAudioDevice then exit;
  3067.   AudioHandShake := FindAudioHandShakeByID(CBAudio.Sender);
  3068.   if AudioHandShake = nil then
  3069.   begin
  3070.     VideoHandShake := FindVideoHandShakeByID(CBAudio.Sender);
  3071.     VideoHandShake.ALastGetTicket := GetTickCount;
  3072.     ChatingForm := VideoHandShake.ChatingForm;
  3073.   end
  3074.   else
  3075.   begin
  3076.     ChatingForm := AudioHandShake.ChatingForm;
  3077.     AudioHandShake.LastGetTicket := GetTickCount;
  3078.   end;
  3079.   if ChatingForm = nil then exit;
  3080.   if ChatingForm.ImgSpkDisabled.Visible then exit;
  3081.   if GetTickCount - AudioLastRestartTime > 5000 then
  3082.   begin
  3083.     AudioLastRestartTime := GetTickCount;
  3084.     ChatingForm.ACMWaveOut.Reset;
  3085.   end;
  3086.   ChatingForm.ACMWaveOut.PlayBack(@(CBAudio.lpData), CBAudio.dwBufferLength);
  3087. end;
  3088. {------------------------------------------------------------------------------}
  3089. procedure TRealMessengerX.ProcessCBSendFileResult(CBSendFileResult: TCBSendFileResult);
  3090. var
  3091.   TransmitFile: TTransmitFile;
  3092.   performancecounter: Int64;
  3093. begin
  3094.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileResult.BaseID));
  3095.   if TransmitFile = nil then exit;
  3096.   if TransmitFile.IsComleted then exit;
  3097.   queryperformancecounter(performancecounter);
  3098.   TransmitFile.SleepValue := (performancecounter - CBSendFileResult.SendTicket) / 10;
  3099.   TransmitFile.LastGetOrResultTicket := GetTickCount;
  3100.   TransmitFile.Send(CBSendFileResult.CurentSize);
  3101. end;
  3102. {------------------------------------------------------------------------------}
  3103. procedure TRealMessengerX.ProcessCBSendFilePackage(CBSendFilePackage: TCBSendFilePackage);
  3104. var
  3105.   TransmitFile: TTransmitFile;
  3106.   Context: MD5Context;
  3107.   MD5CODE: MD5Digest;
  3108. begin
  3109.   MD5Init(Context);
  3110.   MD5Update(Context, PChar(@CBSendFilePackage.Package[1]), CBSendFilePackage.Length);
  3111.   MD5Final(Context, MD5CODE);
  3112.   if not MD5Match(MD5CODE, CBSendFilePackage.MD5CODE) then exit;
  3113.   TransmitFile := FindTransmitFileByBaseID(trim(CBSendFilePackage.BaseID));
  3114.   if TransmitFile = nil then exit;
  3115.   if TransmitFile.IsComleted then exit;
  3116.   TransmitFile.LastGetOrResultTicket := GetTickCount;
  3117.   if not TransmitFile.IsScreen then
  3118.     TransmitFile.FileStream.Position := TransmitFile.FileTable.Count + CBSendFilePackage.Position
  3119.   else
  3120.     TransmitFile.FileStream.Position := CBSendFilePackage.Position;
  3121.   TransmitFile.FileStream.Write(CBSendFilePackage.Package, CBSendFilePackage.Length);
  3122.   TransmitFile.CurentSize := CBSendFilePackage.Position + CBSendFilePackage.Length;
  3123.   TransmitFile.Get(CBSendFilePackage.SendTicket);
  3124. end;
  3125. {------------------------------------------------------------------------------}
  3126. procedure TRealMessengerX.ProcessCBReturnMessage(CBReturnMessage: TCBReturnMessage);
  3127. var
  3128.   iLoop: Integer;
  3129.   CBMessage: TCBMessage;
  3130. begin
  3131.   with MsgReturnCheck.LockList do
  3132.   try
  3133.     for iLoop := Count - 1 downto 0 do
  3134.     begin
  3135.       CBMessage := TCBMessage(Items[iLoop]^);
  3136.       if (CBReturnMessage.Receiver = CBMessage.Sender) and
  3137.         (CBReturnMessage.Sender = CBMessage.Receiver) and
  3138.         (CBReturnMessage.Length = CBMessage.Length) and
  3139.         (CBReturnMessage.SendTicket = CBMessage.SendTicket) then
  3140.       begin
  3141.         MsgReturnCheck.Remove(Items[iLoop]);
  3142.         break;
  3143.       end;
  3144.     end;
  3145.   finally
  3146.     MsgReturnCheck.UnlockList;
  3147.   end;
  3148. end;
  3149. procedure TRealMessengerX.ProcessCBInputing(CBInputing: TCBInputing);
  3150. var
  3151.   ChatingForm: TChatingForm;
  3152. begin
  3153.   ChatingForm := OpenChatingForm(CBInputing.Room, False);
  3154.   if ChatingForm = nil then exit;
  3155.   ChatingForm.ShowInputing(CBInputing.Inputing);
  3156. end;
  3157. {------------------------------------------------------------------------------}
  3158. procedure TRealMessengerX.ProcessCBMessage(CBMessage: TCBMessage);
  3159. var
  3160.   ChatingForm: TChatingForm;
  3161.   iLoop: Integer;
  3162.   PEmployeeData: PEmployee;
  3163.   ReceivedMsgID: PReceivedMsgID;
  3164.   CBReturnMessage: TCBReturnMessage;
  3165.   SendBuffer: array[1..2048] of char;
  3166.   Finded: Boolean;
  3167. begin
  3168.   if (CBMessage.Sender = Me.ID) or (CBMessage.Receiver <> Me.ID) then exit;
  3169.   PEmployeeData := FindEmployeeByID(CBMessage.Sender);
  3170.   if PEmployeeData = nil then exit;
  3171.   Finded := False;
  3172.   if CBMessage.SendTicket <> 0 then
  3173.     with ReceivedMessages.LockList do
  3174.     try
  3175.       for iLoop := Count - 1 downto 0 do
  3176.       begin
  3177.         ReceivedMsgID := Items[iLoop];
  3178.         if (ReceivedMsgID.Sender = CBMessage.Sender) and (ReceivedMsgID.SendTicket = CBMessage.SendTicket) then
  3179.         begin
  3180.           Finded := True;
  3181.           break;
  3182.         end;
  3183.       end;
  3184.     finally
  3185.       ReceivedMessages.UnlockList;
  3186.     end;
  3187.   if CBMessage.SendTicket > 0 then
  3188.   begin
  3189.     CBReturnMessage.Receiver := CBMessage.Sender;
  3190.     CBReturnMessage.Sender := CBMessage.Receiver;
  3191.     CBReturnMessage.Length := CBMessage.Length;
  3192.     CBReturnMessage.SendTicket := CBMessage.SendTicket;
  3193.     SendBuffer[1] := skReturnMessage;
  3194.     CopyMemory(@SendBuffer[2], @CBReturnMessage, SizeOf(CBReturnMessage));
  3195.     if PEmployeeData.MySocket = nil then PEmployeeData.MySocket := TMySocket.Create(PEmployeeData.ID, RealMessengerX.ClientTCP, True);
  3196.     PEmployeeData.MySocket.SendBuffer(SendBuffer, SizeOf(CBReturnMessage) + 1, Finded);
  3197.   end;
  3198.   if not Finded then
  3199.   begin
  3200.     GetMem(ReceivedMsgID, SizeOf(TReceivedMsgID));
  3201.     ReceivedMsgID.Sender := CBMessage.Sender;
  3202.     ReceivedMsgID.SendTicket := CBMessage.SendTicket;
  3203.     ReceivedMessages.Add(ReceivedMsgID);
  3204.     ChatingForm := OpenChatingForm(CBMessage.Room);
  3205.     if ChatingForm = nil then exit;
  3206.     ShowMsg(ChatingForm, ChatingForm.MsgContent, PEmployeeData.Name, CBMessage);
  3207.     if not ChatingForm.Pushed then FlashTray(ChatingForm);
  3208.   end;
  3209. end;
  3210. {------------------------------------------------------------------------------}
  3211. procedure TRealMessengerX.MAVSetsClick(Sender: TObject);
  3212. begin
  3213.   if AVSetForm = nil then AVSetForm := TAVSetForm.Create(Application);
  3214.   try
  3215.     AVSetForm.ShowModal;
  3216.   finally
  3217.     AVSetForm.Free;
  3218.     AVSetForm := nil;
  3219.   end;
  3220. end;
  3221. {------------------------------------------------------------------------------}
  3222. procedure TRealMessengerX.ClientTCPDisconnected(Sender: TObject);
  3223. begin
  3224.   ClientHandleThread.Terminate;
  3225.   ClientLogout();
  3226. end;
  3227. {------------------------------------------------------------------------------}
  3228. procedure TRealMessengerX.ClientTCPConnected(Sender: TObject);
  3229. begin
  3230.   ClientTCP.OnDisconnected := ClientTCPDisconnected;
  3231.   TimerLoging.Enabled := True;
  3232. end;
  3233. procedure TRealMessengerX.TimeCheckTransmitFileErrorTimer(Sender: TObject);
  3234. var
  3235.   iLoop: Integer;
  3236.   TransmitFile: TTransmitFile;
  3237. begin
  3238.   with TransmitFiles.LockList do
  3239.   try
  3240.     if Count = 0 then TimeCheckTransmitFileError.Enabled := False;
  3241.     for iLoop := Count - 1 downto 0 do
  3242.     begin
  3243.       try
  3244.         TransmitFile := Items[iLoop];
  3245.         if (TransmitFile.OnMovingFile = False) and TransmitFile.IsAccepted then
  3246.         begin
  3247.           if ((GetTickCount - TransmitFile.LastGetOrResultTicket) > TimeCheckTransmitFileError.Interval * 3) then
  3248.             TransmitFile.Error
  3249.           else if ((GetTickCount - TransmitFile.LastGetOrResultTicket) > TimeCheckTransmitFileError.Interval) then
  3250.             TransmitFile.MySocket.MySocketCategory := scTCP;
  3251.         end;
  3252.       except
  3253.       end;
  3254.     end;
  3255.   finally
  3256.     TransmitFiles.UnlockList;
  3257.   end;
  3258. end;
  3259. procedure TRealMessengerX.FormResize(Sender: TObject);
  3260. begin
  3261.   if TrevUserList.Visible then ChangeLblMyStateCaption;
  3262. end;
  3263. procedure TRealMessengerX.MsgTimerTimer(Sender: TObject);
  3264. var
  3265.   Buffer: array[1..2048] of char;
  3266.   iLoop, jLoop: Integer;
  3267.   PCB: PCBMessage;
  3268.   EmployeeData: PEmployee;
  3269.   ChatingForm: TChatingForm;
  3270. begin
  3271.   if not ClientTCP.Connected then exit;
  3272.   with MsgReturnCheck.LockList do
  3273.   try
  3274.     if Count = 0 then MsgTimer.Enabled := False;
  3275.     for iLoop := Count - 1 downto 0 do
  3276.     begin
  3277.       PCB := Items[iLoop];
  3278.       if GetTickCount - PCB.SendTicket > MsgTimer.Interval then
  3279.       begin
  3280.         ChatingForm := OpenChatingForm(PCB.Room);
  3281.         EmployeeData := FindEmployeeByID(PCB.Receiver);
  3282.         if ChatingForm = nil then continue;
  3283.         if EmployeeData = nil then continue;
  3284.         if EmployeeData.MySocket = nil then EmployeeData.MySocket := TMySocket.Create(EmployeeData.ID, RealMessengerX.ClientTCP, True);
  3285.         if GetTickCount - PCB.SendTicket > MsgTimer.Interval * 6 then
  3286.         begin
  3287.           ShowMsg(ChatingForm, ChatingForm.MsgContent, '【以下消息没有成功发送给收件人“' + EmployeeData.Name + '”(等待反馈超时)】', PCB^);
  3288.           if not ChatingForm.Pushed then FlashTray(ChatingForm);
  3289.           MsgReturnCheck.Remove(PCB);
  3290.           FreeMem(PCB, SizeOf(TCBMessage));
  3291.         end
  3292.         else
  3293.         begin
  3294.           Buffer[1] := skMessage;
  3295.           CopyMemory(@Buffer[2], PCB, SizeOf(PCB^));
  3296.           if GetTickCount - PCB.SendTicket > MsgTimer.Interval * 3 then EmployeeData.MySocket.MySocketCategory := scTCP; {重试3次失败,启用TCP进行通讯}
  3297.           EmployeeData.MySocket.SendBuffer(Buffer, SizeOf(PCB^) + 1);
  3298.         end;
  3299.       end;
  3300.     end;
  3301.   finally
  3302.     MsgReturnCheck.UnlockList;
  3303.   end;
  3304. end;
  3305. procedure TRealMessengerX.KeepP2PSessionTimerTimer(Sender: TObject);
  3306. var
  3307.   MySocket: TMySocket;
  3308.   iLoop: Integer;
  3309. begin
  3310.   with MySockets.LockList do
  3311.   try
  3312.     for iLoop := Count - 1 downto 0 do
  3313.     begin
  3314.       try
  3315.         MySocket := Items[iLoop];
  3316.         MySocket.KeepP2PSession;
  3317.       except
  3318.       end;
  3319.     end;
  3320.   finally
  3321.     MySockets.UnlockList;
  3322.   end
  3323. end;
  3324. procedure TRealMessengerX.TimerLogingTimer(Sender: TObject);
  3325. begin
  3326.   TimerLoging.Enabled := False;
  3327.   if TrevUserList.Visible = False then
  3328.   begin
  3329.     ClientLogout;
  3330.     CoolTrayIcon.ShowBalloonHint('连接失败', '未能连接至服务器,请检查网络设置!', bitError, 10);
  3331.   end;
  3332. end;
  3333. procedure TRealMessengerX.TimeCheckAVErrorTimer(Sender: TObject);
  3334. var
  3335.   AudioHandShake: TAudioHandShake;
  3336.   VideoHandShake: TVideoHandShake;
  3337.   iLoop, ACount, VCount: Integer;
  3338.   CBPleaseUseTCP: TCBPleaseUseTCP;
  3339.   Buffer: array[1..2048] of char;
  3340. begin
  3341.   with AudioHandShakes.LockList do
  3342.   try
  3343.     ACount := Count;
  3344.     for iLoop := Count - 1 downto 0 do
  3345.     begin
  3346.       AudioHandShake := Items[iLoop];
  3347.       if AudioHandShake.IsAccepted and ((GetTickCount - AudioHandShake.LastGetTicket) > TimeCheckAVError.Interval) then
  3348.       begin
  3349.         CBPleaseUseTCP.Receiver := AudioHandShake.ID;
  3350.         CBPleaseUseTCP.Sender := Me.ID;
  3351.         CBPleaseUseTCP.ForAudioAudio := True;
  3352.         CBPleaseUseTCP.ForVideoAudio := False;
  3353.         CBPleaseUseTCP.ForVideoVideo := False;
  3354.         Buffer[1] := skPleaseUseTCP;
  3355.         CopyMemory(@Buffer[2], @CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
  3356.         ClientTCP.WriteBuffer(Buffer, SizeOf(CBPleaseUseTCP) + 1, True);
  3357.       end;
  3358.     end;
  3359.   finally
  3360.     AudioHandShakes.UnlockList
  3361.   end;
  3362.   with VideoHandShakes.LockList do
  3363.   try
  3364.     VCount := Count;
  3365.     for iLoop := Count - 1 downto 0 do
  3366.     begin
  3367.       VideoHandShake := Items[iLoop];
  3368.       if VideoHandShake.IsAccepted and FindEmployeeByID(VideoHandShake.ID).HaveAudioDevice and ((GetTickCount - VideoHandShake.ALastGetTicket) > TimeCheckAVError.Interval) then
  3369.       begin
  3370.         CBPleaseUseTCP.Receiver := VideoHandShake.ID;
  3371.         CBPleaseUseTCP.Sender := Me.ID;
  3372.         CBPleaseUseTCP.ForAudioAudio := False;
  3373.         CBPleaseUseTCP.ForVideoAudio := True;
  3374.         CBPleaseUseTCP.ForVideoVideo := False;
  3375.         Buffer[1] := skPleaseUseTCP;
  3376.         CopyMemory(@Buffer[2], @CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
  3377.         ClientTCP.WriteBuffer(Buffer, SizeOf(CBPleaseUseTCP) + 1, True);
  3378.       end;
  3379.       if VideoHandShake.IsAccepted and FindEmployeeByID(VideoHandShake.ID).HaveVideoDevice and ((GetTickCount - VideoHandShake.VLastGetTicket) > TimeCheckAVError.Interval) then
  3380.       begin
  3381.         CBPleaseUseTCP.Receiver := VideoHandShake.ID;
  3382.         CBPleaseUseTCP.Sender := Me.ID;
  3383.         CBPleaseUseTCP.ForAudioAudio := False;
  3384.         CBPleaseUseTCP.ForVideoAudio := False;
  3385.         CBPleaseUseTCP.ForVideoVideo := True;
  3386.         Buffer[1] := skPleaseUseTCP;
  3387.         CopyMemory(@Buffer[2], @CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
  3388.         ClientTCP.WriteBuffer(Buffer, SizeOf(CBPleaseUseTCP) + 1, True);
  3389.       end;
  3390.     end;
  3391.   finally
  3392.     VideoHandShakes.UnlockList
  3393.   end;
  3394.   if (ACount = 0) and (VCount = 0) then TimeCheckAVError.Enabled := False;
  3395. end;
  3396. procedure TRealMessengerX.MChangeNameAndPasswordClick(Sender: TObject);
  3397. begin
  3398.   if ChangeNameAndPasswordForm <> nil then exit;
  3399.   ChangeNameAndPasswordForm := TChangeNameAndPasswordForm.Create(Self);
  3400.   ChangeNameAndPasswordForm.Show;
  3401. end;
  3402. procedure TRealMessengerX.bsSkinMenuSpeedButton2Click(Sender: TObject);
  3403. var
  3404.   Point: TPoint;
  3405. begin
  3406.   Point.X := 0;
  3407.   Point.Y := LblFile.Height;
  3408.   PopHelp.Popup(LblFile.ClientToScreen(Point).X - 4, LblFile.ClientToScreen(Point).Y + 2);
  3409. end;
  3410. procedure TRealMessengerX.N14Click(Sender: TObject);
  3411. var
  3412.   Filepath, FileName: string;
  3413. begin
  3414.   Filepath := ExtractFilePath(Application.ExeName);
  3415.   FileName := Filepath + 'help.chm';
  3416.   if fileexists(FileName) then
  3417.     ShellExecute(Handle, 'open', PChar(FileName), nil, PChar(Filepath), sw_ShowNormal);
  3418. end;
  3419. procedure TRealMessengerX.N17Click(Sender: TObject);
  3420. var
  3421.   Filepath, FileName: string;
  3422. begin
  3423.   Filepath := ExtractFilePath(Application.ExeName);
  3424.   FileName := Filepath + 'update.exe';
  3425.   try
  3426.     if fileexists(FileName) then
  3427.       ShellExecute(Handle, 'open', PChar(FileName), nil, PChar(Filepath), SW_SHOW);
  3428.     MExit.click;
  3429.   except
  3430.   end;
  3431. end;
  3432. procedure TRealMessengerX.N16Click(Sender: TObject);
  3433. begin
  3434.   AboutForm := TAboutForm.Create(Self);
  3435.   try
  3436.     AboutForm.ShowModal;
  3437.   finally
  3438.     AboutForm.Free;
  3439.   end;
  3440. end;
  3441. end.