FirstAid.pas
上传用户:hbtcygglw
上传日期:2007-01-07
资源大小:281k
文件大小:4k
- unit FirstAid;
- interface
- uses
- Windows, Messages, SysUtils, Classes,
- Graphics, Controls, Forms, Dialogs,
- StdCtrls, NMUDP, Menus;
- type
- TFirstAidDlg = class(TForm)
- Label1: TLabel;
- edUserId: TEdit;
- Label2: TLabel;
- edPasskey: TEdit;
- UserList: TListBox;
- btnLogon: TButton;
- btnLogoff: TButton;
- btnReadFriend: TButton;
- btnDeleteFriend: TButton;
- UDPSock: TNMUDP;
- lbStatus: TLabel;
- btnName: TButton;
- SaveDlg: TSaveDialog;
- PopupMenu1: TPopupMenu;
- mClear: TMenuItem;
- mSave: TMenuItem;
- procedure FormCreate(Sender: TObject);
- procedure btnLogonClick(Sender: TObject);
- procedure UDPSockDataReceived(Sender: TComponent; NumberBytes: Integer;
- FromIP: String; Port: Integer);
- procedure btnLogoffClick(Sender: TObject);
- procedure btnReadFriendClick(Sender: TObject);
- procedure btnNameClick(Sender: TObject);
- procedure btnDeleteFriendClick(Sender: TObject);
- procedure mClearClick(Sender: TObject);
- procedure mSaveClick(Sender: TObject);
- private
- { Private declarations }
- FMsgId:WORD;
- public
- { Public declarations }
- class procedure Execute;
- end;
- implementation
- {$R *.DFM}
- uses OICQPack;
- { TFirstAidDlg }
- class procedure TFirstAidDlg.Execute;
- begin
- with TFirstAidDlg.Create(Application) do
- begin
- ShowModal;
- Free;
- end;
- end;
- procedure TFirstAidDlg.FormCreate(Sender: TObject);
- begin
- FMsgId:=$0a;
- end;
- procedure TFirstAidDlg.btnLogonClick(Sender: TObject);
- var
- buf:array [0..2048] of char;
- i:Integer;
- begin
- i:=BuildLogonPack(buf,2048,FMsgId,edUserId.Text,edPasskey.Text);
- UDPSock.SendBuffer(buf,i);
- Inc(FMsgId);
- end;
- procedure TFirstAidDlg.UDPSockDataReceived(Sender: TComponent;
- NumberBytes: Integer; FromIP: String; Port: Integer);
- var
- buf:array [0..4096] of char;
- buflen:Integer;
- uid,uname:string;
- begin
- buflen:=4096;
- UDPSock.ReadBuffer(buf,buflen);
- case buf[4] of
- Chr(OICQ_CMD_PING):
- begin
- buflen:=BuildPingPack(buf,4096,FMsgId,edUserId.Text);
- UDPSock.SendBuffer(buf,buflen);
- Inc(FMsgId);
- end;
- Chr(OICQ_CMD_LOGON):
- begin
- lbStatus.Caption:='在线';
- btnLogoff.Enabled:=True;
- btnReadFriend.Enabled:=TRUE;
- btnDeleteFriend.Enabled:=True;
- btnName.Enabled:=True;
- edUserId.Enabled:=False;
- edPasskey.Enabled:=False;
- end;
- Chr(OICQ_CMD_GETUSERINFO):
- begin
- ParseUserInfo(buf,buflen,uid,uname);
- ShowMessage(uid+'='+uname);
- end;
- Chr(OICQ_CMD_GETFRIENDLIST):
- begin
- if(UserList.Items.Count>0)then UserList.Items.Clear;
- ParseFriendList(buf,buflen,UserList.Items);
- end;
- Chr(OICQ_CMD_REMOVEFRIEND):
- begin
- ShowMessage('Remove ok');
- end;
- end;
- end;
- procedure TFirstAidDlg.btnLogoffClick(Sender: TObject);
- var
- buf:array [0..2048] of char;
- i:Integer;
- begin
- i:=BuildLogoffPack(buf,2048,FMsgId,edUserId.Text,edPasskey.Text);
- UDPSock.SendBuffer(buf,i);
- Inc(FMsgId);
- btnLogoff.Enabled:=False;
- btnReadFriend.Enabled:=False;
- btnDeleteFriend.Enabled:=False;
- btnName.Enabled:=False;
- edUserId.Enabled:=True;
- edPasskey.Enabled:=True;
- lbStatus.Caption:='离线';
- end;
- procedure TFirstAidDlg.btnReadFriendClick(Sender: TObject);
- var
- buf:array [0..2048] of char;
- i:Integer;
- begin
- i:=BuildGetFriendListPack(buf,2048,FMsgId,edUserId.Text,edPasskey.Text);
- UDPSock.SendBuffer(buf,i);
- Inc(FMsgId);
- end;
- procedure TFirstAidDlg.btnNameClick(Sender: TObject);
- var
- buf:array [0..1024] of char;
- i:integer;
- id:string;
- begin
- id:=UserList.Items[UserList.ItemIndex];
- i:=BuildGetUserInfoPack(buf,1024,FMsgId,edUserId.Text,id);
- UDPSock.SendBuffer(buf,i);
- Inc(FMsgId);
- end;
- procedure TFirstAidDlg.btnDeleteFriendClick(Sender: TObject);
- var
- buf:array [0..1024] of char;
- i:Integer;
- id:string;
- begin
- id:=UserList.Items[UserList.ItemIndex];
- i:=BuildDeleteFriend(buf,1024,FMsgId,edUserId.Text,id);
- UDPSock.SendBuffer(buf,i);
- Inc(FMsgId);
- end;
- procedure TFirstAidDlg.mClearClick(Sender: TObject);
- begin
- UserList.Items.Clear;
- end;
- procedure TFirstAidDlg.mSaveClick(Sender: TObject);
- begin
- if(SaveDlg.Execute)then
- begin
- UserList.Items.SaveToFile(SaveDlg.FileName);
- end;
- end;
- end.