RealMessengerImpl.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:121k
源码类别:
Delphi控件源码
开发平台:
Delphi
- unit RealMessengerImpl;
- {$WARN SYMBOL_PLATFORM OFF}
- interface
- uses
- Windows, ShellAPI, SysUtils, StrUtils, Classes, Graphics, Controls, Forms, Dialogs,
- ActiveX, AxCtrls, StdVcl, ExtCtrls, StdCtrls, Contnrs,
- ComCtrls, ToolWin, ImgList, UrlMon, MSHtml, MMSystem, Menus, Registry,
- Global, CoolTrayIcon, AppEvnts, Messages, MMPCMSup,
- WinSock, vfw, Color, ShlObj, WNDES, SyncObjs, ChatingFrm,
- RealMessengerUnit, MyInputBoxFrm, SelFaceFrm, MsgFrm, HistoryFrm,
- SystemSetFrm, Tabs, DSUtil, DirectShow9, VideoConsts,
- IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
- IdMessageClient, IdPOP3, Pop3ServerFrm, MMObj, MMDevice, MD5,
- MMMixer, MySocket, IdUDPBase, IdUDPClient,
- IdIOHandler, IdIOHandlerSocket, IdSocks, Gauges, IdAntiFreezeBase,
- IdAntiFreeze, IdHTTP, bsSkinMenus, bsSkinData, BusinessSkinForm,
- OleCtrls, SHDocVw, Mask, bsSkinBoxCtrls, bsSkinCtrls, bsSkinTabs, RxGIF;
- type
- TViewStyle = (vsTree, vsOnlineOffline, vsGroup);
- TRealMessengerX = class(TForm)
- ImgToolbarLeft: TImage;
- ImgTitle: TImage;
- ImgDraw: TImage;
- ImgTitleLeft: TImage;
- ImgTitleRight: TImage;
- ImgToolbarRight: TImage;
- ImgToolbar: TImage;
- ImgBorderLeft: TImage;
- ImgBottomLeft: TImage;
- ImgBottom: TImage;
- ImgBottomRight: TImage;
- ImgBorderRight: TImage;
- ImgClosed: TImage;
- ImgMin: TImage;
- bsSkinPanel1: TbsSkinPanel;
- ImgEmail: TImage;
- LblMyState: TLabel;
- ImgMyState: TImage;
- LblMailCount: TLabel;
- bsSkinMenuSpeedButton1: TbsSkinMenuSpeedButton;
- LblFile: TLabel;
- bsSkinMenuSpeedButton2: TbsSkinMenuSpeedButton;
- PnlRoot: TPanel;
- Image1: TImage;
- bsSkinPageControl1: TbsSkinPageControl;
- bsSkinTabSheet1: TbsSkinTabSheet;
- PnlWorkSpace: TPanel;
- PBLogin: TPanel;
- Gauge: TGauge;
- LblLoging: TLabel;
- LblCancelLogin: TLabel;
- bsSkinScrollBar1: TbsSkinScrollBar;
- bsSkinScrollBar2: TbsSkinScrollBar;
- TrevUserList: TbsSkinTreeView;
- bsSkinPanel3: TbsSkinPanel;
- Image2: TImage;
- edturl: TbsSkinEdit;
- bsSkinPanel4: TbsSkinPanel;
- bsSkinButton2: TbsSkinButton;
- bsSkinPanel5: TbsSkinPanel;
- bsSkinTabSheet2: TbsSkinTabSheet;
- bsSkinPanel2: TbsSkinPanel;
- WBSMS: TWebBrowser;
- bsSkinTabSheet3: TbsSkinTabSheet;
- WBHY: TWebBrowser;
- HartTimer: TTimer;
- PpMenuRight: TPopupMenu;
- NR1: TMenuItem;
- NR2: TMenuItem;
- NR3: TMenuItem;
- NR4: TMenuItem;
- N5: TMenuItem;
- sdfa1: TMenuItem;
- NR5: TMenuItem;
- NSplitOfGroup: TMenuItem;
- NNewGroup: TMenuItem;
- NDelGroup: TMenuItem;
- NAddGroupMember: TMenuItem;
- NRemoveFromGroup: TMenuItem;
- CoolTrayIcon: TCoolTrayIcon;
- ImgLstTrayIcon: TImageList;
- ImgLstMsgAlert: TImageList;
- STimer: TTimer;
- PpMenuStates: TPopupMenu;
- NS1: TMenuItem;
- NS2: TMenuItem;
- NS3: TMenuItem;
- NS4: TMenuItem;
- NS5: TMenuItem;
- NS6: TMenuItem;
- NS7: TMenuItem;
- NS8: TMenuItem;
- N15: TMenuItem;
- NS9: TMenuItem;
- TimerAutoConnect: TTimer;
- TimerTopBar: TTimer;
- PopupMenuShortCut: TPopupMenu;
- N8: TMenuItem;
- ClientPOP3: TIdPOP3;
- Device: TMMMixerDevice;
- TimeCheckTransmitFileError: TTimer;
- ClientTCP: TIdTCPClient;
- IdIOHandlerSocket1: TIdIOHandlerSocket;
- IdSocksInfo1: TIdSocksInfo;
- MsgTimer: TTimer;
- KeepP2PSessionTimer: TTimer;
- ApplicationEvents1: TApplicationEvents;
- TimerLoging: TTimer;
- TimeCheckAVError: TTimer;
- IdAntiFreeze1: TIdAntiFreeze;
- bsBusinessSkinForm1: TbsBusinessSkinForm;
- bsSkinData1: TbsSkinData;
- Skin1: TbsCompressedStoredSkin;
- Timer1: TTimer;
- PopHelp: TbsSkinPopupMenu;
- N14: TMenuItem;
- N16: TMenuItem;
- Timer2: TTimer;
- IdHTTP1: TIdHTTP;
- ImglstTreeIcons: TImageList;
- PopFile: TPopupMenu;
- MOpen: TMenuItem;
- MConnect: TMenuItem;
- MConnectSet: TMenuItem;
- MDisconnect: TMenuItem;
- C1: TMenuItem;
- MChangeNameAndPassword: TMenuItem;
- N3: TMenuItem;
- MMyState: TMenuItem;
- MOnline: TMenuItem;
- MBusy: TMenuItem;
- MWillBack: TMenuItem;
- MLeave: TMenuItem;
- MPhone: TMenuItem;
- MRepast: TMenuItem;
- NMeeting: TMenuItem;
- MOther: TMenuItem;
- N9: TMenuItem;
- MOffline: TMenuItem;
- N2: TMenuItem;
- MAutoLeave: TMenuItem;
- MAutoBusy: TMenuItem;
- N6: TMenuItem;
- MSendMsg: TMenuItem;
- MSendFile: TMenuItem;
- MSendVoice: TMenuItem;
- MSendVideo: TMenuItem;
- N11: TMenuItem;
- MAVSets: TMenuItem;
- N7: TMenuItem;
- MShowHistory: TMenuItem;
- N4: TMenuItem;
- MExit: TMenuItem;
- Label1: TLabel;
- procedure TrevUserListGetImageIndex(Sender: TObject; Node: TTreeNode);
- procedure TrevUserListCustomDrawItem(Sender: TCustomTreeView;
- Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
- procedure MConnectClick(Sender: TObject);
- procedure MTreeClick(Sender: TObject);
- procedure MOnOrOffClick(Sender: TObject);
- procedure MOfflineClick(Sender: TObject);
- procedure MOtherClick(Sender: TObject);
- procedure TrevUserListDblClick(Sender: TObject);
- procedure ClientLogin();
- procedure ClientLogout();
- procedure ActiveFormCreate(Sender: TObject);
- procedure MDisconnectClick(Sender: TObject);
- procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
- procedure LblMyStateClick(Sender: TObject);
- procedure HartTimerTimer(Sender: TObject);
- procedure TrevUserListMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure TrevUserListChange(Sender: TObject; Node: TTreeNode);
- procedure MAutoLeaveClick(Sender: TObject);
- procedure MAutoBusyClick(Sender: TObject);
- procedure NR2Click(Sender: TObject);
- procedure NR3Click(Sender: TObject);
- procedure NR4Click(Sender: TObject);
- procedure CoolTrayIconDblClick(Sender: TObject);
- procedure NR5Click(Sender: TObject);
- procedure TrevUserListMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure STimerTimer(Sender: TObject);
- procedure ActiveFormDestroy(Sender: TObject);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure MExitClick(Sender: TObject);
- procedure FormShow(Sender: TObject);
- procedure TimerAutoConnectTimer(Sender: TObject);
- procedure MGroupClick(Sender: TObject);
- procedure NNewGroupClick(Sender: TObject);
- procedure NDelGroupClick(Sender: TObject);
- procedure NRemoveFromGroupClick(Sender: TObject);
- procedure NAddGroupMemberClick(Sender: TObject);
- procedure MConnectSetClick(Sender: TObject);
- procedure MShowSysHistoryClick(Sender: TObject);
- procedure LblFileClick(Sender: TObject);
- procedure ImgClosedClick(Sender: TObject);
- procedure ImgMinMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure ImgMinMouseUp(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure LblFileMouseMove(Sender: TObject; Shift: TShiftState; X,
- Y: Integer);
- procedure TimerTopBarTimer(Sender: TObject);
- procedure LblFileMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure ImgMinClick(Sender: TObject);
- procedure ImgTitleMouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer);
- procedure LblMailCountClick(Sender: TObject);
- procedure MAVSetsClick(Sender: TObject);
- procedure ClientTCPDisconnected(Sender: TObject);
- procedure ClientTCPConnected(Sender: TObject);
- procedure TimeCheckTransmitFileErrorTimer(Sender: TObject);
- procedure FormResize(Sender: TObject);
- procedure MsgTimerTimer(Sender: TObject);
- procedure KeepP2PSessionTimerTimer(Sender: TObject);
- procedure TimerLogingTimer(Sender: TObject);
- procedure TimeCheckAVErrorTimer(Sender: TObject);
- procedure MChangeNameAndPasswordClick(Sender: TObject);
- procedure bsSkinMenuSpeedButton2Click(Sender: TObject);
- procedure N14Click(Sender: TObject);
- procedure N17Click(Sender: TObject);
- procedure N16Click(Sender: TObject);
- private
- ImgIndex, LastImgIndex: Integer;
- protected
- { Protected declarations }
- public
- IsInIE: Boolean;
- HotKeyMgrIsProcessing: Boolean;
- CurNode: TTreeNode;
- procedure SendIdentity;
- procedure GetInit();
- procedure UpdateListViewStates(TV: TbsSkinTreeView; Node: TTreeNode);
- procedure UpdateMyState();
- procedure ChangeMyState(State: string; IsAutoState: Boolean = False);
- procedure ChangeLblMyStateCaption();
- procedure FlashTray(ChatingForm: TChatingForm);
- procedure Login();
- procedure GetListViewData(TV: TbsSkinTreeView; ViewStyle: TViewStyle = vsTree; IsForSelForm: Boolean = False); //显示用户列表
- procedure TestVideoDevice();
- procedure TestAudioDevice();
- procedure ShowImage(PHandle: HWND; BitMap: HBitMap; Buf: PByte);
- procedure WMDEVICECHANGE(var msgx: Tmessage); message WM_DEVICECHANGE;
- procedure WMMOVE(var Msg: Tmessage); message WM_MOVE;
- procedure ProcessCBInputing(CBInputing: TCBInputing);
- procedure ProcessCBReturnMessage(CBReturnMessage: TCBReturnMessage);
- procedure ProcessCBMessage(CBMessage: TCBMessage);
- procedure ProcessCBSendFileResult(CBSendFileResult: TCBSendFileResult);
- procedure ProcessCBSendFilePackage(CBSendFilePackage: TCBSendFilePackage);
- procedure ProcessCBAudio(CBAudio: TCBAudio);
- procedure ProcessCBVideo(CBVideo: TCBVideo);
- end;
- TClientHandleThread = class(TThread)
- private
- FLock: TCriticalSection;
- CBLoginResult: TCBLoginResult;
- CBSendBranch: TCBSendBranch;
- CBSendEmployee: TCBSendEmployee;
- CBStateChanged: TCBStateChanged;
- CBInputing: TCBInputing;
- CBMessage: TCBMessage;
- CBReturnMessage: TCBReturnMessage;
- CBAddUser: TCBAddUser;
- CBSendFileRequest: TCBSendFileRequest;
- CBSendFileCancle: TCBSendFileCancle;
- CBSendFileStop: TCBSendFileStop;
- CBSendFileResponse: TCBSendFileResponse;
- CBSendFileResult: TCBSendFileResult;
- CBSendFilePackage: TCBSendFilePackage;
- CBSendFileResume: TCBSendFileResume;
- CBSendFileCompleted: TCBSendFileCompleted;
- CBAudioRequest: TCBAudioRequest;
- CBAudioResponse: TCBAudioResponse;
- CBAudioCancel: TCBAudioCancel;
- CBAudio: TCBAudio;
- CBAudioStop: TCBAudioStop;
- CBVideoRequest: TCBVideoRequest;
- CBVideoResponse: TCBVideoResponse;
- CBVideoCancel: TCBVideoCancel;
- CBVideoStop: TCBVideoStop;
- CBSetBitmapInfo: TCBSetBitmapInfo;
- CBSetCompvars: TCBSetCompvars;
- CBVideo: TCBVideo;
- CBBeginTalk: TCBBeginTalk;
- CBPleaseUseTCP: TCBPleaseUseTCP;
- CBNameAndPasswordChanged: TCBNameAndPasswordChanged;
- procedure ProcessCBSendBranch;
- procedure ProcessCBSendEmployee;
- procedure ProcessCBLoginResult;
- procedure ProcessCBStateChanged;
- procedure ProcessCBInputing;
- procedure ProcessCBMessage;
- procedure ProcessCBReturnMessage;
- procedure ProcessCBAddUser;
- procedure ProcessCBSendFileRequest;
- procedure ProcessCBSendFileCancle;
- procedure ProcessCBSendFileStop;
- procedure ProcessCBSendFileResponse;
- procedure ProcessCBSendFileResult;
- procedure ProcessCBSendFilePackage;
- procedure ProcessCBSendFileResume;
- procedure ProcessCBSendFileCompleted;
- procedure ProcessCBAudioRequest;
- procedure ProcessCBAudioResponse;
- procedure ProcessCBAudioCancel;
- procedure ProcessCBAudio;
- procedure ProcessCBAudioStop;
- procedure ProcessCBVideoRequest;
- procedure ProcessCBVideoResponse;
- procedure ProcessCBVideoCancel;
- procedure ProcessCBVideoStop;
- procedure ProcessCBSetBitmapInfo;
- procedure ProcessCBSetCompvars;
- procedure ProcessCBVideo;
- procedure ProcessCBBeginTalk;
- procedure ProcessCBPleaseUseTCP;
- procedure ProcessCBNameAndPasswordChanged;
- public
- constructor Create;
- destructor Destroy; override;
- procedure Execute; override;
- end;
- var
- ConnectedTicket: Cardinal;
- RealMessengerX: TRealMessengerX;
- CheckPOP3ThreadHandle: THandle;
- ClientHandleThread: TClientHandleThread;
- LastMailCount, CurrentMailCount: Integer;
- implementation
- uses ComObj, ComServ, LoginFrm, SelUserFrm, AboutFrm, TempFrm, VideoFrm,
- CopyScreenFrm, AVSetFrm, ChangeNameAndPasswordFrm;
- {$R *.DFM}
- function GetFormNameAt(X, Y: Integer): string;
- var
- P: TPoint;
- W: TWinControl;
- begin
- P.X := X;
- P.Y := Y;
- W := FindVCLWindow(P);
- if (nil <> W) then
- begin
- while W.Parent <> nil do
- W := W.Parent;
- Result := W.Name;
- end
- else
- begin
- Result := '';
- end;
- end;
- {------------------------------------------------------------------------------}
- {邮箱监测}
- function CheckPOP3Thread(Info: Pointer): Integer; stdcall;
- begin
- LastMailCount := -1;
- CurrentMailCount := -1;
- while True do
- begin
- if RealMessengerX.ClientPOP3.Host <> '' then
- begin
- try
- try
- if RealMessengerX.ClientPOP3.Connected then RealMessengerX.ClientPOP3.Disconnect;
- RealMessengerX.ClientPOP3.Connect();
- LastMailCount := CurrentMailCount;
- CurrentMailCount := RealMessengerX.ClientPOP3.CheckMessages;
- RealMessengerX.LblMailCount.Caption := IntToStr(CurrentMailCount) + ' 封电子邮件';
- except
- LastMailCount := -1;
- CurrentMailCount := -1;
- RealMessengerX.LblMailCount.Caption := '未能连接至POP3服务器';
- end;
- finally
- RealMessengerX.ClientPOP3.Disconnect;
- end;
- end
- else
- begin
- RealMessengerX.LblMailCount.Caption := '点击设置您的邮箱';
- end;
- Sleep(60000);
- end;
- Result := 0;
- end;
- {------------------------------------------------------------------------------}
- {
- 功能:设置窗口样式(无标题栏,有边框)
- }
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.WMDEVICECHANGE(var msgx: Tmessage);
- const
- DBT_DEVICEARRIVAL = $8000;
- DBT_DEVICEREMOVECOMPLETE = $8004;
- begin
- inherited;
- if Me = nil then exit;
- TestVideoDevice();
- ChangeMyState(Me.State);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.WMMOVE(var Msg: Tmessage);
- begin
- //
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TestAudioDevice();
- begin
- try
- if Device.DeviceCount > 0 then
- HaveAudioDevice := True
- else
- HaveAudioDevice := False;
- except
- HaveAudioDevice := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TestVideoDevice();
- var
- SysDev: TSysDevEnum;
- begin
- SysDev := TSysDevEnum.Create(CLSID_VideoInputDeviceCategory);
- if SysDev.CountFilters > 0 then
- HaveVideoDevice := True
- else
- HaveVideoDevice := False;
- SysDev.Free;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ActiveFormCreate(Sender: TObject);
- var
- TempReg: TRegistry;
- lgtick1, lgtick2: Int64;
- begin
- queryperformancefrequency(performancefrequency_s);
- performancefrequency_ms := performancefrequency_s / 1000;
- //DoubleBuffered:=True;
- try
- InitCompressor;
- finally
- UnInitCompressor;
- end;
- MySockets := Classes.TThreadList.Create;
- ReceivedMessages := Classes.TThreadList.Create;
- MsgReturnCheck := Classes.TThreadList.Create;
- Branchs := Classes.TThreadList.Create;
- Employees := Classes.TThreadList.Create;
- TransmitFiles := Classes.TThreadList.Create;
- AudioHandShakes := Classes.TThreadList.Create;
- VideoHandShakes := Classes.TThreadList.Create;
- ChatingFormList := TList.Create;
- MsgFormList := TList.Create;
- MsgAlertQueue := TList.Create();
- if ApplicationPath = '' then
- begin
- ApplicationPath := ExtractFilePath(Application.ExeName);
- ResPath := ApplicationPath;
- SoundPath := ApplicationPath + 'Sound';
- CachePath := ApplicationPath + 'Cache';
- HistoryPath := ApplicationPath + 'History';
- PicPath := ApplicationPath + 'Pic';
- end;
- ImgListMain := ImglstTreeIcons;
- TVMain := TrevUserList;
- MACNO := GetNetBIOSAddress;
- CoolTrayIcon.Hint := Application.Title + ' -- 未登录';
- Caption := Application.Title;
- TestAudioDevice();
- TestVideoDevice();
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + 'FormStore', True) then
- begin
- Width := 218;
- Height := Screen.WorkAreaHeight - (Screen.WorkAreaHeight div 3);
- Left := Screen.WorkAreaWidth - 218;
- top := (Screen.WorkAreaHeight - Height) div 2;
- if trim(TempReg.ReadString('Left')) <> '' then Left := StrToInt(TempReg.ReadString('Left'));
- if trim(TempReg.ReadString('Top')) <> '' then top := StrToInt(TempReg.ReadString('Top'));
- if trim(TempReg.ReadString('Width')) <> '' then Width := StrToInt(TempReg.ReadString('Width'));
- if trim(TempReg.ReadString('Height')) <> '' then Height := StrToInt(TempReg.ReadString('Height'));
- end;
- if TempReg.OpenKey(AppKey + 'Login', True) then
- begin
- LoginName := TempReg.ReadString('UserName');
- Password := DESryStrHex(TempReg.ReadString('Password'), DESKEY);
- if trim(TempReg.ReadString('LoginState')) = '' then TempReg.WriteString('LoginState', '联机');
- LoginState := TempReg.ReadString('LoginState');
- HostName := TempReg.ReadString('HostName');
- HostToIP(HostName, HostIP);
- if trim(TempReg.ReadString('ProxyCategory')) = '' then TempReg.WriteString('ProxyCategory', '0');
- ProxyCategory := TProxyCategory(StrToInt(TempReg.ReadString('ProxyCategory')));
- ProxyAddress := TempReg.ReadString('ProxyAddress');
- if TempReg.ReadString('ProxyPort') = '' then TempReg.WriteString('ProxyPort', '1080');
- ProxyPort := StrToInt(TempReg.ReadString('ProxyPort'));
- ProxyUsername := TempReg.ReadString('ProxyUsername');
- ProxyPassword := TempReg.ReadString('ProxyPassword');
- if ProxyAddress <> '' then HostToIP(ProxyAddress, ProxyAddress);
- if TempReg.ReadString('ServerPort') = '' then TempReg.WriteString('ServerPort', '0');
- ServerPort := StrToInt(TempReg.ReadString('ServerPort'));
- if TempReg.ReadString('MsgSound') = '' then TempReg.WriteString('MsgSound', SoundPath + 'Type.wav');
- MsgSound := TempReg.ReadString('MsgSound');
- if TempReg.ReadString('DontPlaySound') = '' then TempReg.WriteString('DontPlaySound', '0');
- DontPlaySound := Boolean(StrToInt(TempReg.ReadString('DontPlaySound')));
- if TempReg.ReadString('AutoConnectInterval') = '' then TempReg.WriteString('AutoConnectInterval', '180');
- AutoConnectInterval := StrToInt(TempReg.ReadString('AutoConnectInterval'));
- if TempReg.ReadString('DontAutoConnect') = '' then TempReg.WriteString('DontAutoConnect', '0');
- DontAutoConnect := Boolean(StrToInt(TempReg.ReadString('DontAutoConnect')));
- if (TempReg.ReadString('SavePass') = '1') and (LoginName <> '') and (HostName <> '') then
- begin
- GetInit();
- SendIdentity();
- end
- else
- begin
- Login();
- end;
- end;
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.GetListViewData(TV: TbsSkinTreeView; ViewStyle: TViewStyle = vsTree; IsForSelForm: Boolean = False);
- var
- iLoop, jLoop, kLoop: Integer;
- BranchPointer, TmpBranch: PBranch;
- EmployeePointer: PEmployee;
- TempReg: TRegistry;
- Keys, Values: TStrings;
- GroupNode: TTreeNode;
- TempEmployees, TempBranchs: TThreadList;
- begin
- OnlineNode := nil;
- OfflineNode := nil;
- if IsForSelForm then
- begin
- TempEmployees := TThreadList.Create;
- TempBranchs := TThreadList.Create;
- with Employees.LockList do
- try
- for iLoop := 0 to Count - 1 do
- begin
- GetMem(EmployeePointer, SizeOf(Employee));
- CopyMemory(EmployeePointer, Items[iLoop], SizeOf(Employee));
- TempEmployees.Add(EmployeePointer);
- end;
- finally
- Employees.UnlockList;
- end;
- with Branchs.LockList do
- try
- for iLoop := 0 to Count - 1 do
- begin
- GetMem(BranchPointer, SizeOf(Employee));
- CopyMemory(BranchPointer, Items[iLoop], SizeOf(Branch));
- TempBranchs.Add(BranchPointer);
- end;
- finally
- Branchs.UnlockList;
- end;
- end
- else
- begin
- TempEmployees := Employees;
- TempBranchs := Branchs;
- end;
- try
- TV.Items.Clear;
- if ViewStyle = vsTree then {显示树型方式}
- begin
- TV.ShowButtons := True;
- TV.ShowLines := True;
- with TempBranchs.LockList do
- try
- for iLoop := 0 to Count - 1 do {添加顶层部门列表}
- begin
- BranchPointer := Items[iLoop];
- BranchPointer.Node := TV.Items.AddChildObject(nil, BranchPointer.Name, BranchPointer);
- BranchPointer.Node.StateIndex := 1 {1表示为部门};
- end; //for
- for iLoop := 0 to Count - 1 do {添加子部门列表}
- begin
- BranchPointer := Items[iLoop];
- for jLoop := 0 to Count - 1 do
- begin
- TmpBranch := Items[jLoop];
- if BranchPointer.ParentID = TmpBranch.ID then
- begin
- BranchPointer.Node.MoveTo(TmpBranch.Node, naAddChild);
- TmpBranch.Node.Expanded := False;
- break;
- end;
- end;
- end;
- finally
- TempBranchs.UnlockList;
- end;
- with TempEmployees.LockList do
- try
- for iLoop := Count - 1 downto 0 do {添加用户列表}
- begin
- EmployeePointer := Items[iLoop];
- with TempBranchs.LockList do
- try
- for jLoop := 0 to Count - 1 do
- begin
- if (PBranch(Items[jLoop])^.ID = EmployeePointer.BranchID) then
- begin
- EmployeePointer.Node := TV.Items.AddChildObjectFirst(PBranch(Items[jLoop])^.Node, EmployeePointer.Name, EmployeePointer);
- EmployeePointer.Node.StateIndex := 2 {2表示为用户};
- UpdateListViewStates(TV, EmployeePointer.Node); {更新用户状态}
- break;
- end;
- end; //for
- finally
- TempBranchs.UnlockList;
- end;
- end; //for
- finally
- TempEmployees.UnlockList;
- end;
- if not IsForSelForm then Me.Node.MakeVisible; {展开当前户名所在的节点}
- end;
- if ViewStyle = vsOnlineOffline then
- begin
- TV.ShowButtons := False;
- TV.ShowLines := False;
- OnlineNode := TV.Items.AddChild(nil, '联机');
- OnlineNode.StateIndex := -1;
- OfflineNode := TV.Items.AddChild(nil, '没有联机');
- OfflineNode.StateIndex := -1;
- with TempEmployees.LockList do
- try
- for iLoop := 0 to Count - 1 do
- begin
- EmployeePointer := Items[iLoop];
- EmployeePointer.Node := TV.Items.AddChildObject(OfflineNode, EmployeePointer.Name, EmployeePointer);
- EmployeePointer.Node.StateIndex := 2;
- UpdateListViewStates(TV, EmployeePointer.Node)
- end;
- finally
- TempEmployees.UnlockList;
- end;
- OfflineNode.Expanded := True;
- end;
- if ViewStyle = vsGroup then {显示组方式}
- begin
- TV.ShowButtons := False;
- TV.ShowLines := False;
- with TempEmployees.LockList do
- try
- for iLoop := 0 to Count - 1 do
- begin
- EmployeePointer := Items[iLoop];
- EmployeePointer.Node := nil;
- end;
- finally
- TempEmployees.UnlockList;
- end;
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if not TempReg.KeyExists(AppKey + '' + LoginName + 'Group') then
- begin
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Group本部门', True) then
- begin
- with TempEmployees.LockList do
- try
- for iLoop := 0 to Count - 1 do
- begin
- EmployeePointer := Items[iLoop];
- if EmployeePointer.BranchID = Me.BranchID then TempReg.WriteString(IntToStr(EmployeePointer.ID), EmployeePointer.LoginName);
- end;
- finally
- TempEmployees.UnlockList;
- end;
- end;
- end;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Group', True) then
- begin
- Keys := TStringList.Create;
- TempReg.GetKeyNames(Keys);
- for iLoop := 0 to Keys.Count - 1 do
- begin
- GroupNode := TV.Items.AddChild(nil, Keys.Strings[iLoop]);
- GroupNode.StateIndex := -1; {-1表示自定义组方式}
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Group' + Keys.Strings[iLoop], True) then
- begin
- Values := TStringList.Create;
- TempReg.GetValueNames(Values);
- for jLoop := 0 to Values.Count - 1 do
- begin
- with TempEmployees.LockList do
- try
- for kLoop := 0 to Count - 1 do
- begin
- EmployeePointer := Items[kLoop];
- if EmployeePointer.ID = StrToInt(Values.Strings[jLoop]) then
- begin
- EmployeePointer.Node := TV.Items.AddChildObject(GroupNode, EmployeePointer.Name, EmployeePointer);
- EmployeePointer.Node.StateIndex := 2 {2表示为用户};
- UpdateListViewStates(TV, EmployeePointer.Node); {更新用户状态}
- end;
- end;
- finally
- TempEmployees.UnlockList
- end;
- end; //for
- Values.Free;
- end; //if
- GroupNode.Expanded := True;
- end; //for
- Keys.Free;
- end; //if
- finally
- TempReg.Free;
- end;
- end;
- if TV.Items.GetFirstNode <> nil then TV.Items.GetFirstNode.Selected := True;
- if TV.Items.GetFirstNode <> nil then TV.Items.GetFirstNode.Selected := False;
- finally
- if IsForSelForm then
- begin
- TempEmployees.Clear;
- TempEmployees.Free;
- TempBranchs.Clear;
- TempBranchs.Free;
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- {更改当前用户的显示状态}
- procedure TRealMessengerX.ChangeLblMyStateCaption();
- var
- iLoop, jLoop, GBBytes, IconIndex: Integer;
- ShowName: string;
- begin
- if Me <> nil then
- begin
- LblMyState.Caption := Me.Name + '(' + Me.State + ')';
- CoolTrayIcon.Hint := Application.Title + ' -- ' + Me.Name + '(' + Me.State + ')';
- IconIndex := 2;
- NS8.Checked := True;
- MOther.Checked := True;
- if Me.State = '断开' then
- begin
- IconIndex := 0;
- NS8.Checked := False;
- MOther.Checked := False;
- end;
- if Me.State = '显示为脱机' then
- begin
- IconIndex := 4;
- NS9.Checked := True;
- MOffline.Checked := True;
- end;
- if Me.State = '联机' then
- begin
- IconIndex := 1;
- NS1.Checked := True;
- MOnline.Checked := True;
- end;
- if Me.State = '忙碌' then
- begin
- IconIndex := 3;
- NS2.Checked := True;
- MBusy.Checked := True;
- end;
- if Me.State = '马上回来' then
- begin
- IconIndex := 2;
- NS3.Checked := True;
- MWillBack.Checked := True;
- end;
- if Me.State = '离开' then
- begin
- IconIndex := 2;
- NS4.Checked := True;
- MLeave.Checked := True;
- end;
- if Me.State = '接听电话' then
- begin
- IconIndex := 3;
- NS5.Checked := True;
- MPhone.Checked := True;
- end;
- if Me.State = '外出就餐' then
- begin
- IconIndex := 2;
- NS6.Checked := True;
- MRepast.Checked := True;
- end;
- if Me.State = '参加会议' then
- begin
- IconIndex := 3;
- NS7.Checked := True;
- NMeeting.Checked := True;
- end;
- end
- else
- begin
- LblMyState.Caption := '未登录';
- CoolTrayIcon.Hint := Application.Title + ' -- 未登录';
- IconIndex := 0;
- end;
- if not CoolTrayIcon.CycleIcons then ImgLstTrayIcon.GetIcon(IconIndex, CoolTrayIcon.Icon);
- if Me = nil then exit;
- iLoop := 1;
- while (LblMyState.Canvas.TextWidth(LblMyState.Caption) > LblMyState.Width) and (iLoop < Length(Me.Name)) do
- begin
- ShowName := Copy(Me.Name, 1, Length(Me.Name) - iLoop);
- GBBytes := 0;
- for jLoop := 1 to Length(ShowName) do
- begin
- if Ord(ShowName[jLoop]) > 128 then Inc(GBBytes);
- end;
- if GBBytes mod 2 <> 0 then ShowName := Copy(ShowName, 1, Length(ShowName) - 1);
- LblMyState.Caption := ShowName + ' ...(' + Me.State + ')';
- Inc(iLoop);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.UpdateMyState();
- begin
- ChangeLblMyStateCaption();
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.UpdateListViewStates(TV: TbsSkinTreeView; Node: TTreeNode);
- var
- BaseImageIndex: Integer;
- Employee: PEmployee;
- begin
- try
- if Node = nil then exit;
- Employee := Node.Data;
- BaseImageIndex := 6;
- Employee.Node.Text := '';
- Employee.Node.ImageIndex := BaseImageIndex;
- if (AnsiSameText(Employee.State, '显示为脱机') or AnsiSameStr(Employee.State, '断开')) then
- begin
- Employee.Node.ImageIndex := BaseImageIndex;
- Employee.Node.Text := Employee.Name;
- if (Employee.Node.Parent <> nil) and (Employee.Node.Parent = OnlineNode) then
- begin
- try
- Employee.Node.MoveTo(OfflineNode, naAddChildFirst);
- if OfflineNode.Count > 0 then OfflineNode.Expanded := True;
- except
- end;
- end;
- exit;
- end;
- if (Employee.Node.Parent = OfflineNode) then
- begin
- try
- Employee.Node.MoveTo(OnlineNode, naAddChildFirst);
- if OnlineNode.Count > 0 then OnlineNode.Expanded := True;
- except
- end;
- end;
- if AnsiSameText(Employee.State, '联机') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 1;
- Employee.Node.Text := Employee.Name;
- exit;
- end;
- if AnsiSameText(Employee.State, '忙碌') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 3;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- exit;
- end;
- if AnsiSameText(Employee.State, '马上回来') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 2;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- exit;
- end;
- if AnsiSameText(Employee.State, '离开') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 2;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- exit;
- end;
- if AnsiSameText(Employee.State, '接听电话') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 3;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- exit;
- end;
- if AnsiSameText(Employee.State, '外出就餐') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 2;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- exit;
- end;
- if AnsiSameText(Employee.State, '参加会议') then
- begin
- Employee.Node.ImageIndex := BaseImageIndex + 3;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- exit;
- end;
- Employee.Node.ImageIndex := BaseImageIndex + 2;
- Employee.Node.Text := Employee.Name + '(' + Employee.State + ')';
- finally
- //TV.Refresh
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TrevUserListGetImageIndex(Sender: TObject;
- Node: TTreeNode);
- begin
- if Node.StateIndex = -1 then
- begin
- if Node.Expanded then
- Node.ImageIndex := 4
- else
- Node.ImageIndex := 5;
- end;
- if Node.StateIndex = 0 then
- begin
- if Node.Expanded then
- Node.ImageIndex := 1
- else
- Node.ImageIndex := 0;
- end;
- if Node.StateIndex = 1 then
- begin
- if Node.Expanded then
- Node.ImageIndex := 3
- else
- Node.ImageIndex := 2;
- end;
- Node.SelectedIndex := Node.ImageIndex;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TrevUserListCustomDrawItem(
- Sender: TCustomTreeView; Node: TTreeNode; State: TCustomDrawState;
- var DefaultDraw: Boolean);
- begin
- DefaultDraw := True;
- if Node.Selected then
- begin
- TrevUserList.Canvas.Font.Color := clWhite;
- end
- else
- begin
- if Node.StateIndex = 2 then
- begin
- if (Node.ImageIndex = 6) or (Node.ImageIndex = 10) then
- TrevUserList.Canvas.Font.Color := clRed
- else
- TrevUserList.Canvas.Font.Color := clGreen;
- end
- else if Node.StateIndex = -1 then
- begin
- TrevUserList.Canvas.Font.Color := $00934A46;
- TrevUserList.Canvas.Font.Style := [fsBold];
- end
- else
- TrevUserList.Canvas.Font.Color := clBlack;
- end;
- TrevUserList.Canvas.Textout(Node.DisplayRect(True).Left + 2, Node.DisplayRect(True).top + 2, Node.Text);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.Login();
- var
- LoginForm: TLoginForm;
- TempReg: TRegistry;
- begin
- LoginForm := TLoginForm.Create(Application);
- try
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + 'Login', True) then
- begin
- LoginForm.EDUserName.Text := TempReg.ReadString('UserName');
- if LoginForm.ShowModal <> mrOK then exit;
- Show;
- TempReg.WriteString('UserName', trim(LoginForm.EDUserName.Text));
- if LoginForm.CBSavePass.Checked then
- begin
- TempReg.WriteString('SavePass', '1');
- TempReg.WriteString('Password', EncryStrHex(trim(LoginForm.EDPassword.Text), DESKEY));
- TempReg.WriteString('LoginState', trim(LoginForm.CBState.Text));
- end
- else
- begin
- TempReg.WriteString('SavePass', '0');
- TempReg.WriteString('Password', '');
- TempReg.WriteString('LoginState', '联机');
- end;
- LoginName := trim(LoginForm.EDUserName.Text);
- Password := trim(LoginForm.EDPassword.Text);
- LoginState := trim(LoginForm.CBState.Text);
- end;
- finally
- TempReg.Free;
- end;
- GetInit();
- SendIdentity();
- finally
- LoginForm.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- {点击了登录菜单}
- procedure TRealMessengerX.MConnectClick(Sender: TObject);
- begin
- if MConnect.Caption = '取消登录(&I)' then
- begin
- ClientLogout();
- end
- else
- begin
- TimerAutoConnect.Enabled := False;
- Login();
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ClientLogin();
- var
- ThreadId: DWORD;
- begin
- if CheckPOP3ThreadHandle = 0 then CheckPOP3ThreadHandle := CreateThread(nil, 0, @CheckPOP3Thread, nil, 0, ThreadId);
- LblMailCount.Enabled := True;
- TimerAutoConnect.Enabled := False;
- TimerLoging.Enabled := False;
- PBLogin.Visible := False;
- LblLoging.Visible := False;
- LblCancelLogin.Visible := False;
- TrevUserList.Show;
- if MAutoLeave.Checked or MAutoBusy.Checked then
- begin
- STimer.Enabled := True;
- Snoop := 0;
- end;
- ConnectedTicket := GetTickCount;
- MConnect.Enabled := False;
- MConnect.Caption := '登录(&I)';
- MConnectSet.Enabled := True;
- MDisconnect.Enabled := True;
- MMyState.Enabled := True;
- MSendMsg.Enabled := True;
- MSendFile.Enabled := True;
- MSendVoice.Enabled := True;
- MSendVideo.Enabled := True;
- MShowHistory.Enabled := True;
- //MChangeNameAndPassword.Enabled :=True;
- NR1.Enabled := True;
- NR2.Enabled := True;
- NR3.Enabled := True;
- NR4.Enabled := True;
- NR5.Enabled := True;
- HartTimer.Enabled := True;
- KeepP2PSessionTimer.Enabled := True;
- LastReturnHartTick := GetTickCount;
- GetListViewData(TrevUserList, vsTree);
- if Me <> nil then
- begin
- UpdateMyState;
- CoolTrayIcon.ShowBalloonHint('登录成功', '您好:' + Me.Name + #13 + '您已登录至 ' + Application.Title + ' 服务器!', bitInfo, 10);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ClientLogout();
- var
- iLoop: Integer;
- EmployeePointer: PEmployee;
- ChatingForm: TChatingForm;
- AudioHandShake: TAudioHandShake;
- VideoHandShake: TVideoHandShake;
- TransmitFile: TTransmitFile;
- MySocket: TMySocket;
- begin
- if ClientTCP.Connected then
- begin
- ClientTCP.OnDisconnected := nil;
- ClientTCP.Disconnect;
- end;
- if CheckPOP3ThreadHandle <> 0 then TerminateThread(CheckPOP3ThreadHandle, 4);
- CheckPOP3ThreadHandle := 0;
- LblMailCount.Caption := '0 封电子邮件';
- LblMailCount.Enabled := False;
- TimerAutoConnect.Enabled := False;
- TimerLoging.Enabled := False;
- KeepP2PSessionTimer.Enabled := False;
- PBLogin.Visible := False;
- LblLoging.Visible := False;
- LblCancelLogin.Visible := False;
- CoolTrayIcon.CycleIcons := False;
- MsgAlertQueue.Clear;
- TrevUserList.Hide;
- STimer.Enabled := False;
- MConnect.Enabled := True;
- MConnect.Caption := '登录(&I)';
- MConnectSet.Enabled := True;
- MDisconnect.Enabled := False;
- MMyState.Enabled := False;
- MSendMsg.Enabled := False;
- MSendFile.Enabled := False;
- MSendVoice.Enabled := False;
- MSendVideo.Enabled := False;
- MShowHistory.Enabled := False;
- MChangeNameAndPassword.Enabled := False;
- NR1.Enabled := False;
- NR2.Enabled := False;
- NR3.Enabled := False;
- NR4.Enabled := False;
- NR5.Enabled := False;
- HartTimer.Enabled := False;
- for iLoop := ChatingFormList.Count - 1 downto 0 do
- begin
- ChatingForm := ChatingFormList.Items[iLoop];
- ChatingFormList.Remove(ChatingForm);
- try
- if (ChatingForm is TChatingForm) then ChatingForm.Free;
- except
- end;
- end;
- with VideoHandShakes.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- VideoHandShake := Items[iLoop];
- VideoHandShake.Free;
- VideoHandShakes.Remove(VideoHandShake);
- end;
- finally
- VideoHandShakes.UnlockList;
- end;
- with AudioHandShakes.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- AudioHandShake := Items[iLoop];
- AudioHandShake.Free;
- AudioHandShakes.Remove(AudioHandShake);
- end;
- finally
- AudioHandShakes.UnlockList;
- end;
- with TransmitFiles.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- TransmitFile := Items[iLoop];
- TransmitFile.Free;
- TransmitFiles.Remove(TransmitFile);
- end;
- finally
- TransmitFiles.UnlockList;
- end;
- with Employees.LockList do
- try
- for iLoop := 0 to Count - 1 do
- begin
- EmployeePointer := Items[iLoop];
- EmployeePointer.State := '断开';
- EmployeePointer.HaveAudioDevice := False;
- EmployeePointer.HaveVideoDevice := False;
- UpdateListViewStates(TrevUserList, EmployeePointer.Node); {更新用户状态}
- FreeMem(EmployeePointer, SizeOf(Employee));
- end;
- finally
- Employees.UnlockList;
- end;
- Employees.Clear;
- with Branchs.LockList do
- try
- for iLoop := 0 to Count - 1 do FreeMem(Items[iLoop], SizeOf(Branch));
- finally
- Branchs.UnlockList;
- end;
- Branchs.Clear;
- UpdateMyState();
- TrevUserList.Items.Clear;
- Me := nil;
- if not DontAutoConnect then
- begin
- TimerAutoConnect.Interval := AutoConnectInterval * 1000;
- TimerAutoConnect.Enabled := True;
- end;
- with MySockets.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- try
- MySocket := Items[iLoop];
- MySocket.Free;
- MySocket := nil;
- except
- end;
- end;
- finally
- MySockets.UnlockList;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.SendIdentity;
- var
- LoginTime: Integer;
- CBLogin: TCBLogin;
- Buffer: array[1..2048] of char;
- StrHttpProxySend, StrHttpProxyRecive: string;
- begin
- if ClientTCP.Connected = False then
- begin
- // showmessage(trim(SystemSetForm.EDHostName.Text));
- // showmessage(SystemSetForm.EDHostName.Text);
- if inet_addr(PChar(HostIP))=INADDR_NONE then
- ClientTCP.Host:=HostName
- else
- ClientTCP.Host:=HostIP;
- ClientTCP.Port:=ServerPort;
- {ClientTCP.Host := trim(SystemSetForm.EDHostName.Text);
- ClientTCP.Port := StrToInt(SystemSetForm.EDHostName.Text);}
- try
- MConnect.Caption := '取消登录(&I)';
- Gauge.Progress := 0;
- PBLogin.Visible := True;
- LblLoging.Caption := '正在连接...';
- LblLoging.Visible := True;
- LblCancelLogin.Visible := True;
- if ProxyCategory <> pcHTTP then
- begin
- IdSocksInfo1.Version := TSocksVersion(ProxyCategory);
- IdSocksInfo1.Host := ProxyAddress;
- IdSocksInfo1.Port := ProxyPort;
- if ProxyUsername = '' then
- begin
- IdSocksInfo1.Authentication := saNoAuthentication;
- end
- else
- begin
- IdSocksInfo1.Authentication := saUsernamePassword;
- IdSocksInfo1.Username := ProxyUsername;
- IdSocksInfo1.Password := ProxyPassword;
- end;
- LoginTime := 0;
- while LoginTime < 3 do
- try
- ClientTCP.Connect(8000);
- break;
- except
- Inc(LoginTime);
- end;
- end
- else
- begin
- IdSocksInfo1.Version := svNoSocks;
- StrHttpProxySend := Format('CONNECT %s:%d HTTP/1.0'#$d#$a#$d#$a + 'Host %s'#$d#$a, [ClientTCP.Host, ClientTCP.Port, ClientTCP.Host]);
- ClientTCP.Host := ProxyAddress;
- ClientTCP.Port := ProxyPort;
- ClientTCP.Connect(8000);
- ClientTCP.Write(StrHttpProxySend);
- StrHttpProxyRecive := ClientTCP.ReadLn; //(EOL);
- ClientTCP.ReadLn;
- ClientTCP.ReadLn;
- if Copy(StrHttpProxyRecive, 1, 12) <> 'HTTP/1.0 200' then ClientTCP.Disconnect;
- end;
- except
- end;
- if not ClientTCP.Connected then
- begin
- ClientLogout;
- CoolTrayIcon.ShowBalloonHint('连接失败', '未能连接至服务器,请检查网络设置!', bitError, 10);
- exit;
- end;
- ClientHandleThread := TClientHandleThread.Create;
- ClientHandleThread.FreeOnTerminate := True;
- ClientHandleThread.Resume;
- end;
- CBLogin.LoginName := LoginName;
- CBLogin.Password := Password;
- CBLogin.State := LoginState;
- CBLogin.LocalIP := GetHostIP('');
- CBLogin.LocalPort := ClientTCP.Socket.Binding.Port;
- CBLogin.HaveAudioDevice := HaveAudioDevice;
- CBLogin.HaveVideoDevice := HaveVideoDevice;
- CBLogin.MACNO := MACNO;
- CBLogin.Version := 40000;
- Buffer[1] := skLogin;
- CopyMemory(@Buffer[2], @CBLogin, SizeOf(CBLogin));
- ClientTCP.Socket.Send(Buffer, SizeOf(CBLogin) + 1);
- LblMyState.Caption := '正在登录...';
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.GetInit();
- var
- TempReg: TRegistry;
- ID: string;
- begin
- ID := LoginName;
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + ID + 'Init', True) then
- begin
- if trim(TempReg.ReadString('ViewStyle')) = '' then
- TempReg.WriteString('ViewStyle', 'Tree');
- if trim(TempReg.ReadString('HiddenState')) = '' then
- TempReg.WriteString('HiddenState', '0');
- if trim(TempReg.ReadString('AutoLeave')) = '' then
- TempReg.WriteString('AutoLeave', '1');
- if trim(TempReg.ReadString('AutoBusy')) = '' then
- TempReg.WriteString('AutoBusy', '1');
- if StrToInt(TempReg.ReadString('AutoLeave')) = 0 then MAutoLeave.Checked := False;
- if StrToInt(TempReg.ReadString('AutoBusy')) = 0 then MAutoBusy.Checked := False;
- if TempReg.ReadString('CustomColor') <> '' then
- begin
- EndColor := TColor(StrToInt(TempReg.ReadString('CustomColor')));
- ChangeAllColor(EndColor);
- end
- else begin
- EndColor := TColor(13816530);
- ChangeAllColor(EndColor);
- end;
- if TempReg.ReadString('POP3Server') <> '' then
- begin
- ClientPOP3.Host := TempReg.ReadString('POP3Server');
- ClientPOP3.Port := StrToInt(TempReg.ReadString('POP3Port'));
- ClientPOP3.Username := TempReg.ReadString('POP3User');
- ClientPOP3.Password := DESryStrHex(TempReg.ReadString('POP3Pass'), DESKEY);
- end
- else
- begin
- LblMailCount.Caption := '点击设置您的邮箱';
- end;
- end;
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- {选择了树型方式查看部门及用户列表}
- procedure TRealMessengerX.MTreeClick(Sender: TObject);
- var
- TempReg: TRegistry;
- begin
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then TempReg.WriteString('ViewStyle', 'Tree');
- finally
- TempReg.Free;
- end;
- GetListViewData(TrevUserList, vsTree);
- end;
- {------------------------------------------------------------------------------}
- {选择了联机/脱机方式查看部门及用户列表}
- procedure TRealMessengerX.MOnOrOffClick(Sender: TObject);
- var
- TempReg: TRegistry;
- begin
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then TempReg.WriteString('ViewStyle', 'OnOrOff');
- finally
- TempReg.Free;
- end;
- GetListViewData(TrevUserList, vsOnlineOffline);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MGroupClick(Sender: TObject);
- var
- TempReg: TRegistry;
- begin
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then TempReg.WriteString('ViewStyle', 'Group');
- finally
- TempReg.Free;
- end;
- GetListViewData(TrevUserList, vsGroup);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ChangeMyState(State: string; IsAutoState: Boolean = False);
- var
- CBStateChanged: TCBStateChanged;
- Buffer: array[1..2048] of char;
- begin
- CBStateChanged.ID := Me.ID;
- CBStateChanged.State := State;
- CBStateChanged.HaveAudioDevice := HaveAudioDevice;
- CBStateChanged.HaveVideoDevice := HaveVideoDevice;
- CBStateChanged.IsAutoState := IsAutoState;
- Buffer[1] := skStateChanged;
- CopyMemory(@Buffer[2], @CBStateChanged, SizeOf(CBStateChanged));
- try
- ClientTCP.WriteBuffer(Buffer, SizeOf(CBStateChanged) + 1, True);
- except
- MessageBox(Handle, '更改状态失败!', '错误', MB_ICONERROR);
- ClientLogout;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MOfflineClick(Sender: TObject);
- begin
- ChangeMyState(Copy(trim((Sender as TMenuItem).Caption), 1, Length(trim((Sender as TMenuItem).Caption)) - 4));
- end;
- {------------------------------------------------------------------------------}
- {用户要自己输入状态值}
- procedure TRealMessengerX.MOtherClick(Sender: TObject);
- var
- InputState: string;
- begin
- InputState := trim(ShowMyInputBox('输入', '您要将当前的状态更改为:', '', 20));
- if Length(InputState) > 0 then
- begin
- ChangeMyState(InputState);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.FlashTray(ChatingForm: TChatingForm);
- begin
- if ChatingForm.Visible then exit;
- if ChatingForm.Pushed then exit;
- ChatingForm.Pushed := True;
- MsgAlertQueue.Add(ChatingForm);
- CoolTrayIcon.IconList := ImgLstMsgAlert;
- CoolTrayIcon.CycleIcons := True;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ShowImage(PHandle: HWND; BitMap: HBitMap; Buf: PByte);
- procedure SetImage(HBitMap: THandle);
- begin
- SendMessage(BitMap, STM_SETIMAGE, IMAGE_BITMAP, Integer(HBitMap));
- end;
- var
- pData: Pointer;
- pDC, MemDC: THandle;
- HBitMap: THandle;
- begin
- pDC := GetDC(PHandle);
- pData := nil;
- HBitMap := CreateDIBSection(0, A_FOutInfo, DIB_RGB_COLORS, pData, 0, 0);
- if not Assigned(pData) and (HBitMap = 0) then
- begin
- Abort;
- end;
- pData := Buf;
- SetImage(HBitMap);
- GdiFlush;
- MemDC := CreateCompatibleDC(pDC);
- SelectObject(MemDC, HBitMap);
- BitBlt(pDC, 0, 0, A_FOutInfo.bmiHeader.biWidth, A_FOutInfo.bmiHeader.biHeight,
- MemDC, 0, 0, SRCCOPY);
- DeleteDC(MemDC);
- end;
- {------------------------------------------------------------------------------}
- {注销}
- procedure TRealMessengerX.MDisconnectClick(Sender: TObject);
- begin
- ClientLogout();
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ApplicationEvents1Exception(Sender: TObject;
- E: Exception);
- begin
- //ShowMessage(E.Message);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.LblMyStateClick(Sender: TObject);
- var
- Point: TPoint;
- begin
- if Me = nil then exit;
- if AnsiSameText(Me.State, '断开') then exit;
- Point.X := 0;
- Point.Y := LblMyState.Height;
- PpMenuStates.Popup(LblMyState.ClientToScreen(Point).X - 18, LblMyState.ClientToScreen(Point).Y + 2);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.HartTimerTimer(Sender: TObject);
- begin
- if ClientTCP.Connected = False then exit;
- try
- ClientTCP.WriteBuffer(skOnlineCheck, 1, True);
- except
- ClientLogout();
- end;
- if GetTickCount - LastReturnHartTick > HartTimer.Interval * 5 then
- begin
- ClientLogout();
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TrevUserListMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- var
- TreeNode: TTreeNode;
- Point: TPoint;
- begin
- TreeNode := TrevUserList.GetNodeAt(X, Y);
- if TreeNode = nil then
- begin
- exit;
- end
- else
- begin
- TreeNode.Selected := False;
- TreeNode.Selected := True;
- end;
- if (Button = mbRight) then
- begin
- Point.X := X;
- Point.Y := Y;
- if (TreeNode.StateIndex = 2) then PpMenuRight.Popup(TrevUserList.ClientToScreen(Point).X, TrevUserList.ClientToScreen(Point).Y);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TrevUserListChange(Sender: TObject;
- Node: TTreeNode);
- begin
- MSendMsg.Enabled := False;
- MSendFile.Enabled := False;
- MSendVoice.Enabled := False;
- MSendVideo.Enabled := False;
- MShowHistory.Enabled := False;
- NR1.Enabled := False;
- NR2.Enabled := False;
- NR3.Enabled := False;
- NR4.Enabled := False;
- NR5.Enabled := False;
- NSplitOfGroup.Visible := True;
- NNewGroup.Visible := True;
- NDelGroup.Visible := True;
- NAddGroupMember.Visible := True;
- NRemoveFromGroup.Visible := True;
- if Node = nil then
- begin
- exit;
- end;
- if (Node.StateIndex = 2) then
- begin
- MSendMsg.Enabled := True;
- MSendFile.Enabled := True;
- MSendVoice.Enabled := True;
- MSendVideo.Enabled := True;
- MShowHistory.Enabled := True;
- NR1.Enabled := True;
- NR2.Enabled := True;
- NR3.Enabled := True;
- NR4.Enabled := True;
- NR5.Enabled := True;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MAutoLeaveClick(Sender: TObject);
- var
- TempReg: TRegistry;
- begin
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then
- if MAutoLeave.Checked then
- begin
- TempReg.WriteString('AutoLeave', '1');
- if STimer.Enabled = False then
- begin
- STimer.Enabled := True;
- Snoop := 0;
- end;
- end
- else
- TempReg.WriteString('AutoLeave', '0')
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MAutoBusyClick(Sender: TObject);
- var
- TempReg: TRegistry;
- begin
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Init', True) then
- if MAutoLeave.Checked then
- begin
- TempReg.WriteString('AutoBusy', '1');
- if STimer.Enabled = False then
- begin
- STimer.Enabled := True;
- Snoop := 0;
- end;
- end
- else
- TempReg.WriteString('AutoBusy', '0')
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TrevUserListDblClick(Sender: TObject);
- var
- ChatingForm: TChatingForm;
- Room: ChatRoom;
- begin
- if TrevUserList.Selected.StateIndex <> 2 then exit;
- if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
- begin
- MessageBox(Handle, '不能与您自己对话!', '提示', MB_ICONINFORMATION);
- exit;
- end;
- Room.UserCount := 2;
- Room.Users[1] := Me.ID;
- Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
- ChatingForm := OpenChatingForm(Room);
- MsgAlertQueue.Remove(ChatingForm);
- if MsgAlertQueue.Count = 0 then
- begin
- CoolTrayIcon.CycleIcons := False;
- CoolTrayIcon.IconList := nil;
- ChangeLblMyStateCaption();
- end;
- ChatingForm.Pushed := True;
- ChatingForm.Show;
- ShowWindow(ChatingForm.Handle, SW_SHOW);
- if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
- if ChatingForm.CanFocus then ChatingForm.SetFocus;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NR2Click(Sender: TObject);
- var
- ChatingForm: TChatingForm;
- Room: ChatRoom;
- begin
- if TrevUserList.Selected.StateIndex <> 2 then exit;
- if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
- begin
- MessageBox(Handle, '不能给您自己发送文件!', '提示', MB_ICONINFORMATION);
- exit;
- end;
- Room.UserCount := 2;
- Room.Users[1] := Me.ID;
- Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
- ChatingForm := OpenChatingForm(Room);
- ChatingForm.Show;
- if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
- if ChatingForm.CanFocus then ChatingForm.SetFocus;
- ChatingForm.ImgSendFileClick(nil);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NR3Click(Sender: TObject);
- var
- ChatingForm: TChatingForm;
- Room: ChatRoom;
- begin
- if TrevUserList.Selected.StateIndex <> 2 then exit;
- if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
- begin
- MessageBox(Handle, '不能与您自己进行音频对话!', '提示', MB_ICONINFORMATION);
- exit;
- end;
- Room.UserCount := 2;
- Room.Users[1] := Me.ID;
- Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
- ChatingForm := OpenChatingForm(Room);
- ChatingForm.Show;
- if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
- if ChatingForm.CanFocus then ChatingForm.SetFocus;
- ChatingForm.ImgVoiceClick(nil);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NR4Click(Sender: TObject);
- var
- ChatingForm: TChatingForm;
- Room: ChatRoom;
- begin
- if TrevUserList.Selected.StateIndex <> 2 then exit;
- if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
- begin
- MessageBox(Handle, '不能与您自己进行视频对话!', '提示', MB_ICONINFORMATION);
- exit;
- end;
- Room.UserCount := 2;
- Room.Users[1] := Me.ID;
- Room.Users[2] := PEmployee(TrevUserList.Selected.Data).ID;
- ChatingForm := OpenChatingForm(Room);
- ChatingForm.Show;
- if ChatingForm.WindowState = wsMinimized then ShowWindow(ChatingForm.Handle, SW_RESTORE);
- if ChatingForm.CanFocus then ChatingForm.SetFocus;
- ChatingForm.ImgVideoClick(nil);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.CoolTrayIconDblClick(Sender: TObject);
- var
- ChatingForm: TChatingForm;
- begin
- try
- if MsgAlertQueue.Count > 0 then
- begin
- ChatingForm := MsgAlertQueue.Items[0];
- MsgAlertQueue.Remove(ChatingForm);
- if ChatingForm <> nil then
- begin
- ChatingForm.Show;
- ShowWindow(ChatingForm.Handle, SW_SHOW);
- if ChatingForm.WindowState = wsMinimized then ChatingForm.WindowState := wsNormal;
- SetForegroundWindow(ChatingForm.Handle);
- end;
- if MsgAlertQueue.Count = 0 then
- begin
- CoolTrayIcon.CycleIcons := False;
- CoolTrayIcon.IconList := nil;
- ChangeLblMyStateCaption();
- end;
- end
- else
- begin
- try
- ShowWindow(Handle, SW_SHOW);
- RealMessengerX.CoolTrayIcon.ShowTaskbarIcon;
- jfForceForeGroundWindow(Handle);
- finally
- MOpen.Visible := False;
- end;
- end;
- except
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NR5Click(Sender: TObject);
- begin
- if TrevUserList.Selected.StateIndex <> 2 then exit;
- if PEmployee(TrevUserList.Selected.Data).ID = Me.ID then
- begin
- MessageBox(Handle, '不存在与您自己的对话记录!', '提示', MB_ICONINFORMATION);
- exit;
- end;
- if HistoryForm <> nil then HistoryForm.Close;
- HistoryForm := THistoryForm.Create(Application);
- HistoryForm.ID := PEmployee(TrevUserList.Selected.Data).ID;
- HistoryForm.Name := PEmployee(TrevUserList.Selected.Data).Name;
- HistoryForm.Show;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TrevUserListMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- var
- Node: TTreeNode;
- P: TPoint;
- begin
- Node := TrevUserList.GetNodeAt(X, Y);
- if Node = nil then
- begin
- Application.CancelHint;
- exit;
- end;
- if (Node.StateIndex <> 1) and (Node.StateIndex <> 2) then
- begin
- Application.CancelHint;
- exit;
- end;
- if Node = CurNode then
- begin
- exit;
- end;
- P.X := Node.DisplayRect(True).Left + TrevUserList.Canvas.TextWidth(Node.Text) + 5;
- P.Y := Node.DisplayRect(True).top + PnlRoot.top;
- if Node.StateIndex = 2 then
- begin
- TrevUserList.Hint := Node.Text + #13 + PEmployee(Node.Data)^.ToolTips
- end
- else
- begin
- Application.CancelHint;
- end;
- Application.ActivateHint(Point(ClientToScreen(P).X, ClientToScreen(P).Y));
- CurNode := Node;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.STimerTimer(Sender: TObject);
- var
- Rct: TRect;
- Point: TPoint;
- Text: array[0..255] of char;
- begin
- if TrevUserList.Visible = False then exit;
- try
- Snoop := Snoop + STimer.Interval;
- GetCursorPos(Point);
- if (OldMousePoint.X <> Point.X) or (OldMousePoint.Y <> Point.Y) then
- begin
- Snoop := 0;
- OldMousePoint.X := Point.X;
- OldMousePoint.Y := Point.Y;
- end;
- if (Snoop > 300000) and MAutoLeave.Checked then //5 分钟之内没有动作
- begin
- if AnsiSameText(Me.State, '联机') then
- begin
- ChangeMyState('离开', True);
- end;
- end
- else if IsAutoState and AnsiSameText(Me.State, '离开') then
- begin
- ChangeMyState('联机');
- end;
- GetClassName(GetForegroundWindow, @Text, 256);
- if (not AnsiSameText(StrPas(Text), 'WorkerW')) and (not AnsiSameText(StrPas(Text), 'Progman')) then
- begin
- GetWindowRect(GetForegroundWindow, Rct);
- IntersectRect(Rct, Rct, Screen.DesktopRect);
- if EqualRect(Rct, Screen.DesktopRect) then //正在运行全屏程序
- begin
- if AnsiSameText(Me.State, '联机') and (MAutoBusy.Checked) and (CopyScreenForm = nil) then
- begin
- ChangeMyState('忙碌', True);
- exit;
- end;
- end
- else if IsAutoState and AnsiSameText(Me.State, '忙碌') then
- begin
- ChangeMyState('联机');
- exit;
- end;
- end;
- except
- end;
- {检测是否有新邮件}
- try
- if (LastMailCount <> -1) and (CurrentMailCount > LastMailCount) then
- begin
- ShowAlert('系统信息', '您收到 ' + IntToStr((CurrentMailCount - LastMailCount)) + ' 封新邮件', True);
- LastMailCount := CurrentMailCount;
- end;
- except
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ActiveFormDestroy(Sender: TObject);
- var
- TempReg: TRegistry;
- begin
- TempReg := TRegistry.Create;
- try
- STimer.Enabled := False;
- HartTimer.Enabled := False;
- TimerAutoConnect.Enabled := False;
- HartTimer.Enabled := False;
- MySockets.Free;
- ReceivedMessages.Free;
- MsgReturnCheck.Free;
- Branchs.Free;
- Employees.Free;
- TransmitFiles.Free;
- AudioHandShakes.Free;
- VideoHandShakes.Free;
- MsgAlertQueue.Free;
- MsgFormList.Free;
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + 'FormStore', True) then
- begin
- TempReg.WriteString('Left', IntToStr(Left));
- TempReg.WriteString('Top', IntToStr(top));
- TempReg.WriteString('Width', IntToStr(Width));
- TempReg.WriteString('Height', IntToStr(Height));
- end;
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.FormClose(Sender: TObject;
- var Action: TCloseAction);
- begin
- Action := caNone;
- ZoomEffect(Self, zaMinimize);
- ShowWindow(RealMessengerX.Handle, SW_HIDE);
- RealMessengerX.CoolTrayIcon.HideTaskbarIcon;
- MOpen.Visible := True;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MExitClick(Sender: TObject);
- begin
- try
- if MDisconnect.Enabled then MDisconnectClick(nil);
- Refresh;
- Sleep(500);
- Close;
- Release;
- finally
- Application.Terminate;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.FormShow(Sender: TObject);
- begin
- ChangeAllColor(EndColor);
- OnShow := nil;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TimerAutoConnectTimer(Sender: TObject);
- begin
- showmessage('1');
- if (not TrevUserList.Visible) and (not DontAutoConnect) and (HostName <> '') and (ServerPort > 0) and (LoginName <> '') and (Password <> '') then
- begin
- SendIdentity();
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NNewGroupClick(Sender: TObject);
- var
- TempReg: TRegistry;
- GroupName: string;
- begin
- GroupName := trim(ShowMyInputBox('输入', '请输入您要新建的组名称:', '', 30));
- if trim(GroupName) = '' then exit;
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.KeyExists(AppKey + '' + LoginName + 'Group' + trim(GroupName)) then
- begin
- MessageBox(Handle, '指定的组已存在!', '提示', MB_ICONINFORMATION);
- exit;
- end
- else
- begin
- TempReg.CreateKey(AppKey + '' + LoginName + 'Group' + trim(GroupName));
- TrevUserList.Items.AddChild(nil, trim(GroupName)).SelectedIndex := -1; {-1表示自定义组方式}
- end;
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NDelGroupClick(Sender: TObject);
- var
- TempReg: TRegistry;
- GroupName: string;
- Node: TTreeNode;
- begin
- Node := TrevUserList.Selected;
- if Node.StateIndex = 2 then Node := Node.Parent;
- GroupName := Node.Text;
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- TempReg.DeleteKey(AppKey + '' + LoginName + 'Group' + trim(GroupName));
- Node.Delete;
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NRemoveFromGroupClick(Sender: TObject);
- var
- TempReg: TRegistry;
- GroupName: string;
- Employee: PEmployee;
- Node: TTreeNode;
- begin
- Node := TrevUserList.Selected.Parent;
- GroupName := Node.Text;
- Employee := PEmployee(TrevUserList.Selected.Data);
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Group' + trim(GroupName), False) then
- begin
- TempReg.DeleteValue(IntToStr(Employee.ID));
- TrevUserList.Selected.Delete;
- Employee.Node := nil;
- end;
- finally
- TempReg.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.NAddGroupMemberClick(Sender: TObject);
- var
- TempReg: TRegistry;
- iLoop, jLoop: Integer;
- Employee1, Employee2: PEmployee;
- GroupName: string;
- GroupNode: TTreeNode;
- begin
- GroupNode := TrevUserList.Selected;
- if GroupNode.StateIndex = 2 then GroupNode := GroupNode.Parent;
- GroupName := GroupNode.Text;
- SelUserForm := TSelUserForm.Create(Self);
- try
- if SelUserForm.ShowModal = mrOK then
- begin
- for iLoop := 0 to SelUserForm.TrevUserList.Items.Count - 1 do
- begin
- if (SelUserForm.TrevUserList.Items[iLoop].ImageIndex < 6) or (SelUserForm.TrevUserList.Items[iLoop].ImageIndex > 13) then continue;
- if IsNodeChecked(SelUserForm.TrevUserList.Items[iLoop]) = False then continue;
- Employee1 := PEmployee(SelUserForm.TrevUserList.Items[iLoop].Data);
- for jLoop := TrevUserList.Items.Count - 1 downto 0 do
- begin
- if TrevUserList.Items[jLoop].StateIndex <> 2 then continue;
- Employee2 := PEmployee(TrevUserList.Items[jLoop].Data);
- if Employee1.ID = Employee2.ID then
- begin
- Employee2.Node.Selected := True;
- NRemoveFromGroupClick(nil);
- end;
- end;
- TempReg := TRegistry.Create;
- try
- TempReg.RootKey := HKEY_LOCAL_MACHINE;
- if TempReg.OpenKey(AppKey + '' + LoginName + 'Group' + trim(GroupName), False) then
- begin
- with Employees.LockList do
- try
- for jLoop := 0 to Count - 1 do
- begin
- Employee2 := Items[jLoop];
- if Employee1.ID = Employee2.ID then
- begin
- TempReg.WriteString(IntToStr(Employee2.ID), Employee2.LoginName);
- Employee2.Node := TrevUserList.Items.AddChildObject(GroupNode, Employee2.Name, Employee2);
- Employee2.Node.StateIndex := 2 {2表示为用户};
- UpdateListViewStates(TrevUserList, Employee2.Node); {更新用户状态}
- break;
- end;
- end;
- finally
- Employees.UnlockList;
- end;
- end;
- finally
- TempReg.Free;
- end;
- end;
- GroupNode.Expanded := True;
- end;
- finally
- SelUserForm.Free;
- SelUserForm := nil;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MConnectSetClick(Sender: TObject);
- begin
- if SystemSetForm <> nil then exit;
- SystemSetForm := TSystemSetForm.Create(Self);
- SystemSetForm.ShowModal;
- SystemSetForm.Free;
- SystemSetForm := nil;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MShowSysHistoryClick(Sender: TObject);
- begin
- if HistoryForm <> nil then HistoryForm.Close;
- HistoryForm := THistoryForm.Create(Application);
- HistoryForm.ID := -1;
- HistoryForm.Name := '系统消息';
- HistoryForm.Show;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.LblFileClick(Sender: TObject);
- var
- Point: TPoint;
- begin
- Point.X := 0;
- Point.Y := LblFile.Height;
- PopFile.Popup(LblFile.ClientToScreen(Point).X - 4, LblFile.ClientToScreen(Point).Y + 2);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ImgClosedClick(Sender: TObject);
- begin
- if MessageBox(Handle, '确定要退出程序吗?', '确认退出', MB_ICONQUESTION or MB_OKCANCEL) = ID_OK then Self.MExitClick(nil);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ImgMinMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- (Sender as TImage).Left := (Sender as TImage).Left + 1;
- (Sender as TImage).top := (Sender as TImage).top + 1;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ImgMinMouseUp(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- (Sender as TImage).Left := (Sender as TImage).Left - 1;
- (Sender as TImage).top := (Sender as TImage).top - 1;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.LblFileMouseMove(Sender: TObject;
- Shift: TShiftState; X, Y: Integer);
- begin
- ImgIndex := (Sender as TLabel).Tag;
- if ImgIndex = LastImgIndex then exit;
- ImgDraw.Canvas.lock;
- with ImgDraw.Canvas do
- begin
- Pen.Mode := pmCopy;
- Pen.Style := psClear;
- Rectangle(0, 0, ImgDraw.Width + 1, ImgDraw.Height + 1);
- Pen.Style := psSolid;
- Pen.Color := $00FEFEFE;
- Pen.Width := 1;
- MoveTo((Sender as TLabel).Left - ImgDraw.Left - 4, 17);
- LineTo(PenPos.X, 0);
- LineTo(PenPos.X + (Sender as TLabel).Width + 4, 0);
- Pen.Color := EndColor;
- LineTo(PenPos.X, 17);
- LineTo(PenPos.X - (Sender as TLabel).Width - 4, 17);
- Pen.Mode := pmWhite;
- Pen.Style := psSolid;
- Refresh;
- end;
- LastImgIndex := ImgIndex;
- TimerTopBar.Enabled := True;
- ImgDraw.Canvas.Unlock;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.TimerTopBarTimer(Sender: TObject);
- var
- P: TPoint;
- begin
- GetCursorPos(P);
- if (P.X < Left + ImgDraw.Left) or
- (P.X > Left + ImgDraw.Left + ImgDraw.Width) or
- (P.Y < top + ImgDraw.top) or
- (P.Y > top + ImgDraw.top + ImgDraw.Height) then
- begin
- with ImgDraw.Canvas do
- begin
- Pen.Mode := pmCopy;
- Pen.Style := psClear;
- Rectangle(0, 0, ImgDraw.Width + 1, ImgDraw.Height + 1);
- end;
- ImgIndex := -1;
- LastImgIndex := -1;
- TimerTopBar.Enabled := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.LblFileMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- ImgDraw.Canvas.lock;
- with ImgDraw.Canvas do
- begin
- Pen.Mode := pmCopy;
- Pen.Style := psClear;
- Rectangle(0, 0, ImgDraw.Width + 1, ImgDraw.Height + 1);
- Pen.Style := psSolid;
- Pen.Color := EndColor;
- Pen.Width := 1;
- MoveTo((Sender as TLabel).Left - ImgDraw.Left - 4, 17);
- LineTo(PenPos.X, 0);
- LineTo(PenPos.X + (Sender as TLabel).Width + 4, 0);
- Pen.Color := $00FEFEFE;
- LineTo(PenPos.X, 17);
- LineTo(PenPos.X - (Sender as TLabel).Width - 4, 17);
- Pen.Mode := pmWhite;
- Pen.Style := psSolid;
- Refresh;
- end;
- TimerTopBar.Enabled := True;
- ImgDraw.Canvas.Unlock;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ImgMinClick(Sender: TObject);
- begin
- Close;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ImgTitleMouseDown(Sender: TObject;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
- begin
- if (Button = mbLeft) then
- begin
- ReleaseCapture;
- Self.Perform(WM_SYSCOMMAND, $F012, 0);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.LblMailCountClick(Sender: TObject);
- var
- ThreadId: DWORD;
- begin
- Pop3ServerForm := TPop3ServerForm.Create(Self);
- try
- if Pop3ServerForm.ShowModal = mrOK then
- begin
- if CheckPOP3ThreadHandle <> 0 then TerminateThread(CheckPOP3ThreadHandle, 4);
- CheckPOP3ThreadHandle := CreateThread(nil, 0, @CheckPOP3Thread, nil, 0, ThreadId);
- end;
- finally
- Pop3ServerForm.Free;
- end;
- end;
- {------------------------------------------------------------------------------}
- constructor TClientHandleThread.Create;
- begin
- inherited Create(True);
- FLock := TCriticalSection.Create;
- Resume;
- end;
- {------------------------------------------------------------------------------}
- destructor TClientHandleThread.Destroy;
- begin
- inherited Destroy;
- FLock.Free;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBLoginResult;
- begin
- if not CBLoginResult.IsLogin then
- begin
- RealMessengerX.ClientLogout;
- RealMessengerX.CoolTrayIcon.ShowBalloonHint('登录失败', CBLoginResult.Result, bitError, 15);
- if (not DontAutoConnect) and (string(CBLoginResult.Result) = ServerStopped) then
- RealMessengerX.TimerAutoConnect.Enabled := True
- else
- RealMessengerX.TimerAutoConnect.Enabled := False;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendBranch;
- var
- PBranchData: PBranch;
- begin
- if CBSendBranch.Current = 0 then Branchs.Clear;
- GetMem(PBranchData, SizeOf(Branch));
- CopyMemory(PBranchData, @(CBSendBranch.BranchData), SizeOf(Branch));
- PBranchData.Node := nil;
- Branchs.Add(PBranchData);
- RealMessengerX.TimerLoging.Enabled := False;
- RealMessengerX.TimerLoging.Enabled := True;
- RealMessengerX.LblLoging.Caption := '正在下载部门列表...';
- RealMessengerX.Gauge.MaxValue := CBSendBranch.Count;
- RealMessengerX.Gauge.Progress := CBSendBranch.Current;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendEmployee;
- var
- PEmployeeData: PEmployee;
- begin
- if CBSendEmployee.Current = 0 then Employees.Clear;
- GetMem(PEmployeeData, SizeOf(Employee));
- CopyMemory(PEmployeeData, @(CBSendEmployee.EmployeeData), SizeOf(Employee));
- PEmployeeData.Node := nil;
- PEmployeeData.MySocket := nil;
- Employees.Add(PEmployeeData);
- if PEmployeeData.LoginName = LoginName then Me := PEmployeeData;
- if CBSendEmployee.Current = CBSendEmployee.Count then
- begin
- RealMessengerX.ClientLogin;
- end
- else
- begin
- RealMessengerX.TimerLoging.Enabled := False;
- RealMessengerX.TimerLoging.Enabled := True;
- RealMessengerX.LblLoging.Caption := '正在下载帐号列表...';
- RealMessengerX.Gauge.MaxValue := CBSendEmployee.Count;
- RealMessengerX.Gauge.Progress := CBSendEmployee.Current;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBNameAndPasswordChanged;
- var
- jLoop: Integer;
- PEmployeeData, Employee1: PEmployee;
- begin
- PEmployeeData := FindEmployeeByID(CBNameAndPasswordChanged.ID);
- if PEmployeeData = nil then exit;
- PEmployeeData.Name := CBNameAndPasswordChanged.Name;
- RealMessengerX.UpdateListViewStates(RealMessengerX.TrevUserList, PEmployeeData.Node);
- if SelUserForm <> nil then
- begin
- for jLoop := 0 to SelUserForm.TrevUserList.Items.Count - 1 do
- begin
- if (SelUserForm.TrevUserList.Items[jLoop].ImageIndex < 6) or (SelUserForm.TrevUserList.Items[jLoop].ImageIndex > 13) then continue;
- Employee1 := PEmployee(SelUserForm.TrevUserList.Items[jLoop].Data);
- if Employee1.ID = PEmployeeData.ID then
- begin
- Employee1.State := PEmployeeData.State;
- RealMessengerX.UpdateListViewStates(SelUserForm.TrevUserList, Employee1.Node);
- break;
- end;
- end;
- end;
- if PEmployeeData.ID = Me.ID then
- begin
- IsAutoState := CBStateChanged.IsAutoState;
- RealMessengerX.UpdateMyState;
- end;
- for jLoop := 0 to ChatingFormList.Count - 1 do TChatingForm(ChatingFormList.Items[jLoop]).ShowTitle;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBStateChanged;
- var
- iLoop, jLoop: Integer;
- PEmployeeData, Employee1: PEmployee;
- TransmitFile: TTransmitFile;
- AudioHandShake: TAudioHandShake;
- VideoHandShake: TVideoHandShake;
- begin
- PEmployeeData := FindEmployeeByID(CBStateChanged.ID);
- if PEmployeeData = nil then exit;
- if AnsiSameText(CBStateChanged.State, '断开') then
- begin
- with TransmitFiles.LockList do
- try
- for jLoop := Count - 1 downto 0 do
- begin
- TransmitFile := Items[jLoop];
- if ((TransmitFile.SenderID = CBStateChanged.ID) or (TransmitFile.ReceiverID = CBStateChanged.ID)) and (TransmitFile.IsComleted = False) then TransmitFile.Logout;
- end;
- finally
- TransmitFiles.UnlockList;
- end;
- with AudioHandShakes.LockList do
- try
- for jLoop := Count - 1 downto 0 do
- begin
- AudioHandShake := Items[jLoop];
- if AudioHandShake.ID = CBStateChanged.ID then AudioHandShake.Logout;
- end;
- finally
- AudioHandShakes.UnlockList;
- end;
- with VideoHandShakes.LockList do
- try
- for jLoop := Count - 1 downto 0 do
- begin
- VideoHandShake := Items[jLoop];
- if VideoHandShake.ID = CBStateChanged.ID then VideoHandShake.Logout;
- end;
- finally
- VideoHandShakes.UnlockList;
- end;
- PEmployeeData.MySocket.Free;
- PEmployeeData.MySocket := nil;
- end;
- if (PEmployeeData.ID <> Me.ID) and (GetTickCount - ConnectedTicket > 10000) then
- begin
- if (AnsiSameText(CBStateChanged.State, '显示为脱机') or AnsiSameText(CBStateChanged.State, '断开')) and (not AnsiSameText(PEmployeeData.State, '显示为脱机') and not AnsiSameText(PEmployeeData.State, '断开')) then
- begin
- PlayEventSound(SoundPath + 'out.wav');
- ShowAlert('系统信息', PEmployeeData.Name + ' 刚刚离线', True); ;
- end;
- if (AnsiSameText(PEmployeeData.State, '显示为脱机') or AnsiSameText(PEmployeeData.State, '断开')) and (not AnsiSameText(CBStateChanged.State, '显示为脱机') and not AnsiSameText(CBStateChanged.State, '断开')) then
- begin
- PlayEventSound(SoundPath + 'in.wav');
- ShowAlert('系统信息', PEmployeeData.Name + ' 刚刚上线', True); ;
- end;
- end;
- PEmployeeData.State := CBStateChanged.State;
- PEmployeeData.HaveAudioDevice := CBStateChanged.HaveAudioDevice;
- PEmployeeData.HaveVideoDevice := CBStateChanged.HaveVideoDevice;
- RealMessengerX.UpdateListViewStates(RealMessengerX.TrevUserList, PEmployeeData.Node); //更新用户状态
- if SelUserForm <> nil then
- begin
- for jLoop := 0 to SelUserForm.TrevUserList.Items.Count - 1 do
- begin
- if (SelUserForm.TrevUserList.Items[jLoop].ImageIndex < 6) or (SelUserForm.TrevUserList.Items[jLoop].ImageIndex > 13) then continue;
- Employee1 := PEmployee(SelUserForm.TrevUserList.Items[jLoop].Data);
- if Employee1.ID = PEmployeeData.ID then
- begin
- Employee1.State := PEmployeeData.State;
- RealMessengerX.UpdateListViewStates(SelUserForm.TrevUserList, Employee1.Node); //更新用户状态
- break;
- end;
- end;
- end;
- if PEmployeeData.ID = Me.ID then
- begin
- IsAutoState := CBStateChanged.IsAutoState;
- RealMessengerX.UpdateMyState;
- end;
- for jLoop := 0 to ChatingFormList.Count - 1 do TChatingForm(ChatingFormList.Items[jLoop]).ShowTitle;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBBeginTalk;
- var
- PEmployeeData: PEmployee;
- begin
- PEmployeeData := FindEmployeeByID(CBBeginTalk.Sender);
- if PEmployeeData = nil then exit;
- if PEmployeeData.MySocket = nil then
- begin
- PEmployeeData.MySocket := TMySocket.Create(PEmployeeData.ID, RealMessengerX.ClientTCP, True);
- end;
- PEmployeeData.MySocket.ReceiverLocalIP := CBBeginTalk.LocalIP;
- PEmployeeData.MySocket.ReceiverLocalPort := CBBeginTalk.LocalPort;
- PEmployeeData.MySocket.ReceiverIP := CBBeginTalk.IP;
- PEmployeeData.MySocket.ReceiverPort := CBBeginTalk.Port;
- PEmployeeData.MySocket.BeginGetHole;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBPleaseUseTCP;
- var
- AudioHandShake: TAudioHandShake;
- VideoHandShake: TVideoHandShake;
- iLoop: Integer;
- ChatingForm: TChatingForm;
- begin
- if CBPleaseUseTCP.ForAudioAudio then
- begin
- with AudioHandShakes.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- AudioHandShake := Items[iLoop];
- if AudioHandShake.IsAccepted and (AudioHandShake.ID = CBPleaseUseTCP.Sender) then
- begin
- ChatingForm := AudioHandShake.ChatingForm;
- if not ChatingForm.ImgMicDisabled.Visible then AudioHandShake.MySocket.MySocketCategory := scTCP;
- end;
- end;
- finally
- AudioHandShakes.UnlockList
- end;
- end
- else
- begin
- with VideoHandShakes.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- VideoHandShake := Items[iLoop];
- if VideoHandShake.IsAccepted and (VideoHandShake.ID = CBPleaseUseTCP.Sender) then
- begin
- if CBPleaseUseTCP.ForVideoAudio then
- begin
- ChatingForm := VideoHandShake.ChatingForm;
- if not ChatingForm.ImgMicDisabled.Visible then VideoHandShake.AMySocket.MySocketCategory := scTCP;
- end
- else
- begin
- VideoHandShake.VMySocket.MySocketCategory := scTCP;
- end;
- end;
- end;
- finally
- VideoHandShakes.UnlockList
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBInputing;
- begin
- RealMessengerX.ProcessCBInputing(CBInputing);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBAddUser;
- var
- iLoop: Integer;
- ChatingForm: TChatingForm;
- begin
- ChatingForm := OpenChatingForm(CBAddUser.Room, False);
- if ChatingForm = nil then exit;
- for iLoop := 1 to CBAddUser.AddRoom.UserCount do
- begin
- ChatingForm.RoomInfo.UserCount := ChatingForm.RoomInfo.UserCount + 1;
- ChatingForm.RoomInfo.Users[ChatingForm.RoomInfo.UserCount] := CBAddUser.AddRoom.Users[iLoop];
- end;
- ChatingForm.ShowTitle;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileRequest;
- var
- iLoop: Integer;
- ChatingForm: TChatingForm;
- PEmployeeData: PEmployee;
- begin
- ChatingForm := OpenChatingForm(CBSendFileRequest.Room, True);
- if ChatingForm = nil then exit;
- PEmployeeData := FindEmployeeByID(CBSendFileRequest.Sender);
- if PEmployeeData = nil then exit;
- 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);
- if not ChatingForm.Pushed then RealMessengerX.FlashTray(ChatingForm);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileResponse;
- var
- TransmitFile: TTransmitFile;
- ChatingForm: TChatingForm;
- begin
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileResponse.BaseID));
- if TransmitFile = nil then exit;
- TransmitFile.MySocket.ReceiverLocalIP := CBSendFileResponse.LocalIP;
- TransmitFile.MySocket.ReceiverLocalPort := CBSendFileResponse.LocalPort;
- TransmitFile.MySocket.ReceiverIP := CBSendFileResponse.IP;
- TransmitFile.MySocket.ReceiverPort := CBSendFileResponse.Port;
- TransmitFile.MySocket.BeginGetHole;
- ChatingForm := TransmitFile.ChatingForm;
- if ChatingForm = nil then exit;
- if CBSendFileResponse.IsAccept then
- TransmitFile.Accept
- else
- begin
- TransmitFile.Decline;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileResult;
- begin
- RealMessengerX.ProcessCBSendFileResult(CBSendFileResult);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFilePackage;
- begin
- RealMessengerX.ProcessCBSendFilePackage(CBSendFilePackage);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileResume;
- var
- iLoop: Integer;
- TransmitFile: TTransmitFile;
- E: IHTMLElement;
- begin
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileResume.BaseID));
- if TransmitFile = nil then exit;
- E := (TransmitFile.ChatingForm.MsgContent.Document as IHTMLDocument2).all.item(TransmitFile.PercentID, 0) as IHTMLElement;
- E.innerHTML := '准备发送文件(正在接收断点续传信息)...';
- for iLoop := 0 to CBSendFileResume.BufferLength - 1 do
- begin
- PFileTableUnit(TransmitFile.FileTable.Items[CBSendFileResume.Start + iLoop]).IsAccepted := CBSendFileResume.ResumBuffer[iLoop + 1];
- if PFileTableUnit(TransmitFile.FileTable.Items[CBSendFileResume.Start + iLoop]).IsAccepted = '1' then TransmitFile.ResumedSize := TransmitFile.ResumedSize + FilePackSize;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileCompleted;
- var
- TransmitFile: TTransmitFile;
- begin
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileCompleted.BaseID));
- if TransmitFile = nil then exit;
- TransmitFile.IsComleted := True;
- TMoveFile.Create(TransmitFile);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileCancle;
- var
- TransmitFile: TTransmitFile;
- ChatingForm: TChatingForm;
- begin
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileCancle.BaseID));
- if TransmitFile = nil then exit;
- ChatingForm := TransmitFile.ChatingForm;
- if ChatingForm = nil then exit;
- TransmitFile.Cancel;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSendFileStop;
- var
- TransmitFile: TTransmitFile;
- ChatingForm: TChatingForm;
- begin
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileStop.BaseID));
- if TransmitFile = nil then exit;
- ChatingForm := TransmitFile.ChatingForm;
- if ChatingForm = nil then exit;
- TransmitFile.Stop(CBSendFileStop.Sender);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSetBitmapInfo;
- begin
- FillChar(A_FInInfo, SizeOf(A_FInInfo), 0);
- Move(CBSetBitmapInfo.Buf, A_FInInfo, SizeOf(A_FInInfo));
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBSetCompvars;
- begin
- FillChar(A_FCV, SizeOf(A_FCV), 0);
- Move(CBSetCompvars.Buf, A_FCV, SizeOf(A_FCV));
- A_FCV.hic := ICOpen(A_FCV.fccType, A_FCV.fccHandler, ICMODE_DECOMPRESS);
- if A_FCV.hic = 0 then
- begin
- MessageBox(RealMessengerX.Handle, '您的机器未安装系统所需的MPEG4解码器!', '提示', MB_ICONINFORMATION);
- end else
- begin
- A_FOutFormatSize := ICDecompressGetFormatSize(A_FCV.hic, @A_FInInfo.bmiHeader);
- FillChar(A_FOutInfo, SizeOf(A_FOutInfo), 0);
- ICDecompressGetFormat(A_FCV.hic, @A_FInInfo, @A_FOutInfo);
- FOutBufSize := A_FOutInfo.bmiHeader.biSizeImage;
- if Assigned(FOutBuf) then FreeMem(FOutBuf);
- GetMem(FOutBuf, FOutBufSize);
- FillChar(FOutBuf^, FOutBufSize, 0);
- ICDecompressBegin(A_FCV.hic, @A_FInInfo, @A_FOutInfo);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBVideo;
- begin
- RealMessengerX.ProcessCBVideo(CBVideo);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBMessage;
- begin
- RealMessengerX.ProcessCBMessage(CBMessage);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBReturnMessage;
- begin
- RealMessengerX.ProcessCBReturnMessage(CBReturnMessage);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBAudioRequest;
- var
- ChatingForm: TChatingForm;
- PEmployeeData: PEmployee;
- begin
- PEmployeeData := FindEmployeeByID(CBAudioRequest.Sender);
- if PEmployeeData = nil then exit;
- ChatingForm := OpenChatingForm(CBAudioRequest.Room, True);
- if ChatingForm = nil then exit;
- TAudioHandShake.Create(ahResponse, PEmployeeData.ID, PEmployeeData.Name, ChatingForm, CBAudioRequest.LocalIP, CBAudioRequest.LocalPort, CBAudioRequest.IP, CBAudioRequest.Port);
- if not ChatingForm.Pushed then RealMessengerX.FlashTray(ChatingForm);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBAudioResponse;
- var
- ChatingForm: TChatingForm;
- AudioHandShake: TAudioHandShake;
- begin
- AudioHandShake := FindAudioHandShakeByID(CBAudioResponse.Sender);
- if AudioHandShake = nil then exit;
- AudioHandShake.MySocket.ReceiverLocalIP := CBAudioResponse.LocalIP;
- AudioHandShake.MySocket.ReceiverLocalPort := CBAudioResponse.LocalPort;
- AudioHandShake.MySocket.ReceiverIP := CBAudioResponse.IP;
- AudioHandShake.MySocket.ReceiverPort := CBAudioResponse.Port;
- AudioHandShake.MySocket.BeginGetHole;
- ChatingForm := AudioHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- if CBAudioResponse.isAcepted then
- AudioHandShake.Accept
- else
- AudioHandShake.Decline;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBAudioCancel;
- var
- ChatingForm: TChatingForm;
- AudioHandShake: TAudioHandShake;
- begin
- AudioHandShake := FindAudioHandShakeByID(CBAudioCancel.Sender);
- if AudioHandShake = nil then exit;
- ChatingForm := AudioHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- AudioHandShake.Cancel;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBAudio;
- begin
- RealMessengerX.ProcessCBAudio(CBAudio);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBAudioStop;
- var
- ChatingForm: TChatingForm;
- AudioHandShake: TAudioHandShake;
- begin
- AudioHandShake := FindAudioHandShakeByID(CBAudioStop.Sender);
- if AudioHandShake = nil then exit;
- ChatingForm := AudioHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- AudioHandShake.Stop(CBAudioStop.Sender);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBVideoRequest;
- var
- ChatingForm: TChatingForm;
- PEmployeeData: PEmployee;
- begin
- PEmployeeData := FindEmployeeByID(CBVideoRequest.Sender);
- if PEmployeeData = nil then exit;
- ChatingForm := OpenChatingForm(CBVideoRequest.Room, True);
- if ChatingForm = nil then exit;
- TVideoHandShake.Create(vhResponse, PEmployeeData.ID, PEmployeeData.Name, ChatingForm,
- CBVideoRequest.ALocalIP, CBVideoRequest.ALocalPort, CBVideoRequest.AIP, CBVideoRequest.APort,
- CBVideoRequest.VLocalIP, CBVideoRequest.VLocalPort, CBVideoRequest.VIP, CBVideoRequest.VPort);
- if not ChatingForm.Pushed then RealMessengerX.FlashTray(ChatingForm);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBVideoResponse;
- var
- ChatingForm: TChatingForm;
- VideoHandShake: TVideoHandShake;
- begin
- VideoHandShake := FindVideoHandShakeByID(CBVideoResponse.Sender);
- if VideoHandShake = nil then exit;
- VideoHandShake.AMySocket.ReceiverLocalIP := CBVideoResponse.ALocalIP;
- VideoHandShake.AMySocket.ReceiverLocalPort := CBVideoResponse.ALocalPort;
- VideoHandShake.AMySocket.ReceiverIP := CBVideoResponse.AIP;
- VideoHandShake.AMySocket.ReceiverPort := CBVideoResponse.APort;
- VideoHandShake.AMySocket.BeginGetHole;
- VideoHandShake.VMySocket.ReceiverLocalIP := CBVideoResponse.VLocalIP;
- VideoHandShake.VMySocket.ReceiverLocalPort := CBVideoResponse.VLocalPort;
- VideoHandShake.VMySocket.ReceiverIP := CBVideoResponse.VIP;
- VideoHandShake.VMySocket.ReceiverPort := CBVideoResponse.VPort;
- VideoHandShake.VMySocket.BeginGetHole;
- ChatingForm := VideoHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- if CBVideoResponse.isAcepted then
- VideoHandShake.Accept
- else
- VideoHandShake.Decline;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBVideoCancel;
- var
- ChatingForm: TChatingForm;
- VideoHandShake: TVideoHandShake;
- begin
- VideoHandShake := FindVideoHandShakeByID(CBVideoCancel.Sender);
- if VideoHandShake = nil then exit;
- ChatingForm := VideoHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- VideoHandShake.Cancel;
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.ProcessCBVideoStop;
- var
- ChatingForm: TChatingForm;
- VideoHandShake: TVideoHandShake;
- begin
- VideoHandShake := FindVideoHandShakeByID(CBVideoStop.Sender);
- if VideoHandShake = nil then exit;
- ChatingForm := VideoHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- VideoHandShake.Stop(CBVideoStop.Sender);
- end;
- {------------------------------------------------------------------------------}
- procedure TClientHandleThread.Execute;
- var
- skType: char;
- begin
- while not Terminated do
- begin
- if not RealMessengerX.ClientTCP.Connected then
- Terminate
- else
- try
- RealMessengerX.ClientTCP.ReadBuffer(skType, 1);
- {************************************************************************}
- if skType = skLoginResult then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBLoginResult, SizeOf(CBLoginResult));
- Synchronize(ProcessCBLoginResult);
- continue;
- end;
- {************************************************************************}
- if skType = skSendBranch then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendBranch, SizeOf(CBSendBranch));
- Synchronize(ProcessCBSendBranch);
- continue;
- end;
- {************************************************************************}
- if skType = skSendEmployee then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendEmployee, SizeOf(CBSendEmployee));
- Synchronize(ProcessCBSendEmployee);
- continue;
- end;
- {************************************************************************}
- if skType = skStateChanged then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBStateChanged, SizeOf(CBStateChanged));
- Synchronize(ProcessCBStateChanged);
- continue;
- end;
- {************************************************************************}
- if skType = skOnlineCheck then
- begin
- LastReturnHartTick := GetTickCount;
- continue;
- end;
- {************************************************************************}
- if skType = skBeginTalk then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBBeginTalk, SizeOf(CBBeginTalk));
- Synchronize(ProcessCBBeginTalk);
- continue;
- end;
- {************************************************************************}
- if skType = skInputing then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBInputing, SizeOf(CBInputing));
- Synchronize(ProcessCBInputing);
- continue;
- end;
- {************************************************************************}
- if skType = skMessage then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBMessage, SizeOf(CBMessage));
- Synchronize(ProcessCBMessage);
- continue;
- end;
- {************************************************************************}
- if skType = skReturnMessage then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBReturnMessage, SizeOf(CBReturnMessage));
- Synchronize(ProcessCBReturnMessage);
- continue;
- end;
- {************************************************************************}
- if skType = skAddUser then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBAddUser, SizeOf(CBAddUser));
- Synchronize(ProcessCBAddUser);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileRequest then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileRequest, SizeOf(CBSendFileRequest));
- Synchronize(ProcessCBSendFileRequest);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileCancle then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileCancle, SizeOf(CBSendFileCancle));
- Synchronize(ProcessCBSendFileCancle);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileStop then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileStop, SizeOf(CBSendFileStop));
- Synchronize(ProcessCBSendFileStop);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileResponse then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileResponse, SizeOf(CBSendFileResponse));
- Synchronize(ProcessCBSendFileResponse);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFilePackage then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFilePackage, SizeOf(CBSendFilePackage));
- Synchronize(ProcessCBSendFilePackage);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileResult then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileResult, SizeOf(CBSendFileResult));
- Synchronize(ProcessCBSendFileResult);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileResume then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileResume, SizeOf(CBSendFileResume));
- Synchronize(ProcessCBSendFileResume);
- continue;
- end;
- {************************************************************************}
- if skType = skSendFileCompleted then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSendFileCompleted, SizeOf(CBSendFileCompleted));
- Synchronize(ProcessCBSendFileCompleted);
- continue;
- end;
- {************************************************************************}
- if skType = skAudioRequest then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBAudioRequest, SizeOf(CBAudioRequest));
- Synchronize(ProcessCBAudioRequest);
- continue;
- end;
- {************************************************************************}
- if skType = skAudioResponse then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBAudioResponse, SizeOf(CBAudioResponse));
- Synchronize(ProcessCBAudioResponse);
- continue;
- end;
- {************************************************************************}
- if skType = skAudioCancel then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBAudioCancel, SizeOf(CBAudioCancel));
- Synchronize(ProcessCBAudioCancel);
- continue;
- end;
- {************************************************************************}
- if skType = skAudio then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBAudio, SizeOf(CBAudio));
- Synchronize(ProcessCBAudio);
- continue;
- end;
- {************************************************************************}
- if skType = skAudioStop then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBAudioStop, SizeOf(CBAudioStop));
- Synchronize(ProcessCBAudioStop);
- continue;
- end;
- {************************************************************************}
- if skType = skVideoRequest then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBVideoRequest, SizeOf(CBVideoRequest));
- Synchronize(ProcessCBVideoRequest);
- continue;
- end;
- {************************************************************************}
- if skType = skVideoResponse then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBVideoResponse, SizeOf(CBVideoResponse));
- Synchronize(ProcessCBVideoResponse);
- continue;
- end;
- {************************************************************************}
- if skType = skVideoCancel then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBVideoCancel, SizeOf(CBVideoCancel));
- Synchronize(ProcessCBVideoCancel);
- continue;
- end;
- {************************************************************************}
- if skType = skVideoStop then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBVideoStop, SizeOf(CBVideoStop));
- Synchronize(ProcessCBVideoStop);
- continue;
- end;
- {************************************************************************}
- if skType = skSetBitmapInfo then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSetBitmapInfo, SizeOf(CBSetBitmapInfo));
- Synchronize(ProcessCBSetBitmapInfo);
- continue;
- end;
- {************************************************************************}
- if skType = skSetCompvars then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBSetCompvars, SizeOf(CBSetCompvars));
- Synchronize(ProcessCBSetCompvars);
- continue;
- end;
- {************************************************************************}
- if skType = skVideo then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBVideo, SizeOf(CBVideo));
- Synchronize(ProcessCBVideo);
- continue;
- end;
- {************************************************************************}
- if skType = skPleaseUseTCP then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
- Synchronize(ProcessCBPleaseUseTCP);
- continue;
- end;
- {************************************************************************}
- if skType = skNameAndPasswordChanged then
- begin
- RealMessengerX.ClientTCP.ReadBuffer(CBNameAndPasswordChanged, SizeOf(CBNameAndPasswordChanged));
- Synchronize(ProcessCBNameAndPasswordChanged);
- continue;
- end;
- except
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ProcessCBVideo(CBVideo: TCBVideo);
- var
- VideoHandShake: TVideoHandShake;
- ChatingForm: TChatingForm;
- RetVal, FPS, SPEED: Integer;
- SPEEDSTR: string;
- begin
- VideoHandShake := FindVideoHandShakeByID(CBVideo.Sender);
- if VideoHandShake = nil then exit;
- VideoHandShake.VLastGetTicket := GetTickCount;
- ChatingForm := VideoHandShake.ChatingForm;
- if ChatingForm = nil then exit;
- if CBVideo.nSampleNum = 0 then
- begin
- VideoHandShake.StartTicket := GetTickCount;
- VideoHandShake.GetedData := 0;
- VideoHandShake.GetedFrame := 0;
- end;
- if (CBVideo.PackNO = 1) then
- begin
- FillChar(VideoHandShake.VideoData, SizeOf(TVideoDataInfo), 0);
- VideoHandShake.VideoData.bKeyFrame := CBVideo.bKeyFrame;
- VideoHandShake.VideoData.nSampleNum := CBVideo.nSampleNum;
- VideoHandShake.VideoData.nUsedSize := CBVideo.nAllSize;
- VideoHandShake.VideoData.nGetedSize := 0;
- end;
- if VideoHandShake.VideoData.nSampleNum <> CBVideo.nSampleNum then exit;
- if (VideoHandShake.VideoData.nGetedSize <> (CBVideo.PackNO - 1) * SizeOf(CBVideo.Buf)) then exit;
- CopyMemory(@(VideoHandShake.VideoData.Buf[VideoHandShake.VideoData.nGetedSize]), @(CBVideo.Buf[1]), CBVideo.BufLength);
- VideoHandShake.VideoData.nGetedSize := VideoHandShake.VideoData.nGetedSize + CBVideo.BufLength;
- if CBVideo.PackNO = CBVideo.PackCount then
- begin
- if (VideoHandShake.VideoData.nUsedSize > 0) and (VideoHandShake.VideoData.nUsedSize < 8180) then
- begin
- RetVal := ICDeCompress(A_FCV.hic, 0, @A_FInInfo.bmiHeader, @VideoHandShake.VideoData.Buf[0],
- @A_FOutInfo.bmiHeader, FOutBuf);
- if RetVal = ICERR_OK then
- begin
- try
- if VideoForm = nil then
- begin
- StretchDIBits(VideoHandShake.pDC,
- 0, 0,
- 160,
- 120,
- 0, 0,
- A_FOutInfo.bmiHeader.biWidth,
- A_FOutInfo.bmiHeader.biHeight,
- FOutBuf, A_FOutInfo, DIB_RGB_COLORS, SRCCOPY);
- end
- else
- StretchDIBits(VideoHandShake.pDC,
- 0, 0,
- VideoForm.ClientWidth,
- VideoForm.ClientHeight,
- 0, 0,
- A_FOutInfo.bmiHeader.biWidth,
- A_FOutInfo.bmiHeader.biHeight,
- FOutBuf, A_FOutInfo, DIB_RGB_COLORS, SRCCOPY)
- except
- end;
- VideoHandShake.GetedData := VideoHandShake.GetedData + SizeOf(CBVideo.Buf);
- VideoHandShake.GetedFrame := VideoHandShake.GetedFrame + 1;
- if GetTickCount - VideoHandShake.StartTicket > 1000 then
- begin
- FPS := VideoHandShake.GetedFrame * 1000 div (GetTickCount - VideoHandShake.StartTicket);
- SPEED := (VideoHandShake.GetedData * 1000 div (GetTickCount - VideoHandShake.StartTicket));
- if SPEED > 1024 then
- SPEEDSTR := IntToStr(SPEED div 1024) + 'K/S'
- else
- SPEEDSTR := '1K/S';
- if VideoForm = nil then
- ChatingForm.LblFPS.Caption := IntToStr(FPS) + 'FPS,' + SPEEDSTR
- else
- VideoForm.Caption := IntToStr(FPS) + 'FPS,' + SPEEDSTR;
- VideoHandShake.StartTicket := GetTickCount;
- VideoHandShake.GetedData := 0;
- VideoHandShake.GetedFrame := 0;
- end;
- end;
- FillChar(VideoHandShake.VideoData, SizeOf(TVideoDataInfo), 0);
- end;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ProcessCBAudio(CBAudio: TCBAudio);
- var
- ChatingForm: TChatingForm;
- AudioHandShake: TAudioHandShake;
- VideoHandShake: TVideoHandShake;
- begin
- if not HaveAudioDevice then exit;
- AudioHandShake := FindAudioHandShakeByID(CBAudio.Sender);
- if AudioHandShake = nil then
- begin
- VideoHandShake := FindVideoHandShakeByID(CBAudio.Sender);
- VideoHandShake.ALastGetTicket := GetTickCount;
- ChatingForm := VideoHandShake.ChatingForm;
- end
- else
- begin
- ChatingForm := AudioHandShake.ChatingForm;
- AudioHandShake.LastGetTicket := GetTickCount;
- end;
- if ChatingForm = nil then exit;
- if ChatingForm.ImgSpkDisabled.Visible then exit;
- if GetTickCount - AudioLastRestartTime > 5000 then
- begin
- AudioLastRestartTime := GetTickCount;
- ChatingForm.ACMWaveOut.Reset;
- end;
- ChatingForm.ACMWaveOut.PlayBack(@(CBAudio.lpData), CBAudio.dwBufferLength);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ProcessCBSendFileResult(CBSendFileResult: TCBSendFileResult);
- var
- TransmitFile: TTransmitFile;
- performancecounter: Int64;
- begin
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFileResult.BaseID));
- if TransmitFile = nil then exit;
- if TransmitFile.IsComleted then exit;
- queryperformancecounter(performancecounter);
- TransmitFile.SleepValue := (performancecounter - CBSendFileResult.SendTicket) / 10;
- TransmitFile.LastGetOrResultTicket := GetTickCount;
- TransmitFile.Send(CBSendFileResult.CurentSize);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ProcessCBSendFilePackage(CBSendFilePackage: TCBSendFilePackage);
- var
- TransmitFile: TTransmitFile;
- Context: MD5Context;
- MD5CODE: MD5Digest;
- begin
- MD5Init(Context);
- MD5Update(Context, PChar(@CBSendFilePackage.Package[1]), CBSendFilePackage.Length);
- MD5Final(Context, MD5CODE);
- if not MD5Match(MD5CODE, CBSendFilePackage.MD5CODE) then exit;
- TransmitFile := FindTransmitFileByBaseID(trim(CBSendFilePackage.BaseID));
- if TransmitFile = nil then exit;
- if TransmitFile.IsComleted then exit;
- TransmitFile.LastGetOrResultTicket := GetTickCount;
- if not TransmitFile.IsScreen then
- TransmitFile.FileStream.Position := TransmitFile.FileTable.Count + CBSendFilePackage.Position
- else
- TransmitFile.FileStream.Position := CBSendFilePackage.Position;
- TransmitFile.FileStream.Write(CBSendFilePackage.Package, CBSendFilePackage.Length);
- TransmitFile.CurentSize := CBSendFilePackage.Position + CBSendFilePackage.Length;
- TransmitFile.Get(CBSendFilePackage.SendTicket);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ProcessCBReturnMessage(CBReturnMessage: TCBReturnMessage);
- var
- iLoop: Integer;
- CBMessage: TCBMessage;
- begin
- with MsgReturnCheck.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- CBMessage := TCBMessage(Items[iLoop]^);
- if (CBReturnMessage.Receiver = CBMessage.Sender) and
- (CBReturnMessage.Sender = CBMessage.Receiver) and
- (CBReturnMessage.Length = CBMessage.Length) and
- (CBReturnMessage.SendTicket = CBMessage.SendTicket) then
- begin
- MsgReturnCheck.Remove(Items[iLoop]);
- break;
- end;
- end;
- finally
- MsgReturnCheck.UnlockList;
- end;
- end;
- procedure TRealMessengerX.ProcessCBInputing(CBInputing: TCBInputing);
- var
- ChatingForm: TChatingForm;
- begin
- ChatingForm := OpenChatingForm(CBInputing.Room, False);
- if ChatingForm = nil then exit;
- ChatingForm.ShowInputing(CBInputing.Inputing);
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ProcessCBMessage(CBMessage: TCBMessage);
- var
- ChatingForm: TChatingForm;
- iLoop: Integer;
- PEmployeeData: PEmployee;
- ReceivedMsgID: PReceivedMsgID;
- CBReturnMessage: TCBReturnMessage;
- SendBuffer: array[1..2048] of char;
- Finded: Boolean;
- begin
- if (CBMessage.Sender = Me.ID) or (CBMessage.Receiver <> Me.ID) then exit;
- PEmployeeData := FindEmployeeByID(CBMessage.Sender);
- if PEmployeeData = nil then exit;
- Finded := False;
- if CBMessage.SendTicket <> 0 then
- with ReceivedMessages.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- ReceivedMsgID := Items[iLoop];
- if (ReceivedMsgID.Sender = CBMessage.Sender) and (ReceivedMsgID.SendTicket = CBMessage.SendTicket) then
- begin
- Finded := True;
- break;
- end;
- end;
- finally
- ReceivedMessages.UnlockList;
- end;
- if CBMessage.SendTicket > 0 then
- begin
- CBReturnMessage.Receiver := CBMessage.Sender;
- CBReturnMessage.Sender := CBMessage.Receiver;
- CBReturnMessage.Length := CBMessage.Length;
- CBReturnMessage.SendTicket := CBMessage.SendTicket;
- SendBuffer[1] := skReturnMessage;
- CopyMemory(@SendBuffer[2], @CBReturnMessage, SizeOf(CBReturnMessage));
- if PEmployeeData.MySocket = nil then PEmployeeData.MySocket := TMySocket.Create(PEmployeeData.ID, RealMessengerX.ClientTCP, True);
- PEmployeeData.MySocket.SendBuffer(SendBuffer, SizeOf(CBReturnMessage) + 1, Finded);
- end;
- if not Finded then
- begin
- GetMem(ReceivedMsgID, SizeOf(TReceivedMsgID));
- ReceivedMsgID.Sender := CBMessage.Sender;
- ReceivedMsgID.SendTicket := CBMessage.SendTicket;
- ReceivedMessages.Add(ReceivedMsgID);
- ChatingForm := OpenChatingForm(CBMessage.Room);
- if ChatingForm = nil then exit;
- ShowMsg(ChatingForm, ChatingForm.MsgContent, PEmployeeData.Name, CBMessage);
- if not ChatingForm.Pushed then FlashTray(ChatingForm);
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.MAVSetsClick(Sender: TObject);
- begin
- if AVSetForm = nil then AVSetForm := TAVSetForm.Create(Application);
- try
- AVSetForm.ShowModal;
- finally
- AVSetForm.Free;
- AVSetForm := nil;
- end;
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ClientTCPDisconnected(Sender: TObject);
- begin
- ClientHandleThread.Terminate;
- ClientLogout();
- end;
- {------------------------------------------------------------------------------}
- procedure TRealMessengerX.ClientTCPConnected(Sender: TObject);
- begin
- ClientTCP.OnDisconnected := ClientTCPDisconnected;
- TimerLoging.Enabled := True;
- end;
- procedure TRealMessengerX.TimeCheckTransmitFileErrorTimer(Sender: TObject);
- var
- iLoop: Integer;
- TransmitFile: TTransmitFile;
- begin
- with TransmitFiles.LockList do
- try
- if Count = 0 then TimeCheckTransmitFileError.Enabled := False;
- for iLoop := Count - 1 downto 0 do
- begin
- try
- TransmitFile := Items[iLoop];
- if (TransmitFile.OnMovingFile = False) and TransmitFile.IsAccepted then
- begin
- if ((GetTickCount - TransmitFile.LastGetOrResultTicket) > TimeCheckTransmitFileError.Interval * 3) then
- TransmitFile.Error
- else if ((GetTickCount - TransmitFile.LastGetOrResultTicket) > TimeCheckTransmitFileError.Interval) then
- TransmitFile.MySocket.MySocketCategory := scTCP;
- end;
- except
- end;
- end;
- finally
- TransmitFiles.UnlockList;
- end;
- end;
- procedure TRealMessengerX.FormResize(Sender: TObject);
- begin
- if TrevUserList.Visible then ChangeLblMyStateCaption;
- end;
- procedure TRealMessengerX.MsgTimerTimer(Sender: TObject);
- var
- Buffer: array[1..2048] of char;
- iLoop, jLoop: Integer;
- PCB: PCBMessage;
- EmployeeData: PEmployee;
- ChatingForm: TChatingForm;
- begin
- if not ClientTCP.Connected then exit;
- with MsgReturnCheck.LockList do
- try
- if Count = 0 then MsgTimer.Enabled := False;
- for iLoop := Count - 1 downto 0 do
- begin
- PCB := Items[iLoop];
- if GetTickCount - PCB.SendTicket > MsgTimer.Interval then
- begin
- ChatingForm := OpenChatingForm(PCB.Room);
- EmployeeData := FindEmployeeByID(PCB.Receiver);
- if ChatingForm = nil then continue;
- if EmployeeData = nil then continue;
- if EmployeeData.MySocket = nil then EmployeeData.MySocket := TMySocket.Create(EmployeeData.ID, RealMessengerX.ClientTCP, True);
- if GetTickCount - PCB.SendTicket > MsgTimer.Interval * 6 then
- begin
- ShowMsg(ChatingForm, ChatingForm.MsgContent, '【以下消息没有成功发送给收件人“' + EmployeeData.Name + '”(等待反馈超时)】', PCB^);
- if not ChatingForm.Pushed then FlashTray(ChatingForm);
- MsgReturnCheck.Remove(PCB);
- FreeMem(PCB, SizeOf(TCBMessage));
- end
- else
- begin
- Buffer[1] := skMessage;
- CopyMemory(@Buffer[2], PCB, SizeOf(PCB^));
- if GetTickCount - PCB.SendTicket > MsgTimer.Interval * 3 then EmployeeData.MySocket.MySocketCategory := scTCP; {重试3次失败,启用TCP进行通讯}
- EmployeeData.MySocket.SendBuffer(Buffer, SizeOf(PCB^) + 1);
- end;
- end;
- end;
- finally
- MsgReturnCheck.UnlockList;
- end;
- end;
- procedure TRealMessengerX.KeepP2PSessionTimerTimer(Sender: TObject);
- var
- MySocket: TMySocket;
- iLoop: Integer;
- begin
- with MySockets.LockList do
- try
- for iLoop := Count - 1 downto 0 do
- begin
- try
- MySocket := Items[iLoop];
- MySocket.KeepP2PSession;
- except
- end;
- end;
- finally
- MySockets.UnlockList;
- end
- end;
- procedure TRealMessengerX.TimerLogingTimer(Sender: TObject);
- begin
- TimerLoging.Enabled := False;
- if TrevUserList.Visible = False then
- begin
- ClientLogout;
- CoolTrayIcon.ShowBalloonHint('连接失败', '未能连接至服务器,请检查网络设置!', bitError, 10);
- end;
- end;
- procedure TRealMessengerX.TimeCheckAVErrorTimer(Sender: TObject);
- var
- AudioHandShake: TAudioHandShake;
- VideoHandShake: TVideoHandShake;
- iLoop, ACount, VCount: Integer;
- CBPleaseUseTCP: TCBPleaseUseTCP;
- Buffer: array[1..2048] of char;
- begin
- with AudioHandShakes.LockList do
- try
- ACount := Count;
- for iLoop := Count - 1 downto 0 do
- begin
- AudioHandShake := Items[iLoop];
- if AudioHandShake.IsAccepted and ((GetTickCount - AudioHandShake.LastGetTicket) > TimeCheckAVError.Interval) then
- begin
- CBPleaseUseTCP.Receiver := AudioHandShake.ID;
- CBPleaseUseTCP.Sender := Me.ID;
- CBPleaseUseTCP.ForAudioAudio := True;
- CBPleaseUseTCP.ForVideoAudio := False;
- CBPleaseUseTCP.ForVideoVideo := False;
- Buffer[1] := skPleaseUseTCP;
- CopyMemory(@Buffer[2], @CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
- ClientTCP.WriteBuffer(Buffer, SizeOf(CBPleaseUseTCP) + 1, True);
- end;
- end;
- finally
- AudioHandShakes.UnlockList
- end;
- with VideoHandShakes.LockList do
- try
- VCount := Count;
- for iLoop := Count - 1 downto 0 do
- begin
- VideoHandShake := Items[iLoop];
- if VideoHandShake.IsAccepted and FindEmployeeByID(VideoHandShake.ID).HaveAudioDevice and ((GetTickCount - VideoHandShake.ALastGetTicket) > TimeCheckAVError.Interval) then
- begin
- CBPleaseUseTCP.Receiver := VideoHandShake.ID;
- CBPleaseUseTCP.Sender := Me.ID;
- CBPleaseUseTCP.ForAudioAudio := False;
- CBPleaseUseTCP.ForVideoAudio := True;
- CBPleaseUseTCP.ForVideoVideo := False;
- Buffer[1] := skPleaseUseTCP;
- CopyMemory(@Buffer[2], @CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
- ClientTCP.WriteBuffer(Buffer, SizeOf(CBPleaseUseTCP) + 1, True);
- end;
- if VideoHandShake.IsAccepted and FindEmployeeByID(VideoHandShake.ID).HaveVideoDevice and ((GetTickCount - VideoHandShake.VLastGetTicket) > TimeCheckAVError.Interval) then
- begin
- CBPleaseUseTCP.Receiver := VideoHandShake.ID;
- CBPleaseUseTCP.Sender := Me.ID;
- CBPleaseUseTCP.ForAudioAudio := False;
- CBPleaseUseTCP.ForVideoAudio := False;
- CBPleaseUseTCP.ForVideoVideo := True;
- Buffer[1] := skPleaseUseTCP;
- CopyMemory(@Buffer[2], @CBPleaseUseTCP, SizeOf(CBPleaseUseTCP));
- ClientTCP.WriteBuffer(Buffer, SizeOf(CBPleaseUseTCP) + 1, True);
- end;
- end;
- finally
- VideoHandShakes.UnlockList
- end;
- if (ACount = 0) and (VCount = 0) then TimeCheckAVError.Enabled := False;
- end;
- procedure TRealMessengerX.MChangeNameAndPasswordClick(Sender: TObject);
- begin
- if ChangeNameAndPasswordForm <> nil then exit;
- ChangeNameAndPasswordForm := TChangeNameAndPasswordForm.Create(Self);
- ChangeNameAndPasswordForm.Show;
- end;
- procedure TRealMessengerX.bsSkinMenuSpeedButton2Click(Sender: TObject);
- var
- Point: TPoint;
- begin
- Point.X := 0;
- Point.Y := LblFile.Height;
- PopHelp.Popup(LblFile.ClientToScreen(Point).X - 4, LblFile.ClientToScreen(Point).Y + 2);
- end;
- procedure TRealMessengerX.N14Click(Sender: TObject);
- var
- Filepath, FileName: string;
- begin
- Filepath := ExtractFilePath(Application.ExeName);
- FileName := Filepath + 'help.chm';
- if fileexists(FileName) then
- ShellExecute(Handle, 'open', PChar(FileName), nil, PChar(Filepath), sw_ShowNormal);
- end;
- procedure TRealMessengerX.N17Click(Sender: TObject);
- var
- Filepath, FileName: string;
- begin
- Filepath := ExtractFilePath(Application.ExeName);
- FileName := Filepath + 'update.exe';
- try
- if fileexists(FileName) then
- ShellExecute(Handle, 'open', PChar(FileName), nil, PChar(Filepath), SW_SHOW);
- MExit.click;
- except
- end;
- end;
- procedure TRealMessengerX.N16Click(Sender: TObject);
- begin
- AboutForm := TAboutForm.Create(Self);
- try
- AboutForm.ShowModal;
- finally
- AboutForm.Free;
- end;
- end;
- end.