1. UDS Messenger file
2. UDS Messenger Ver 1.0.0.2 Updates
- Add a message send and receive the UDS Messenger Client DLL function
- Client (EXE) to connect to distinguish Client DLL connect and display.
- On a chat screen is displayed in the Windows TaskBar
- Adding Client DLL's main form of message passing features in the chat window (after the message, type CTRL + SHIFT + ENTER)
3. How to put a program in the Messenger client
[ Source Code(Delphi) ]
1) DLL for connecting Type
type
TCreateChatForm = function(AMainHandle: HWND; AId, APwd, APName: PChar; AIsAutoLogin: Boolean): HWND; cdecl; //Create function chat form
TSendMessage = function(AId, AMsg: PChar; ASendMethod: Integer): Boolean; cdecl; //Message transfer function
TDestoryChatForm = procedure; cdecl; //Turn off chat Form Memory
2) Variable declaration
private
FChatFormHwnd: HWND;//Save chat window handle value of
FChatFormLib: THandle; //The value of the handle of the DLL Chat
public
Procedure WMCopyData(var AMsg: TWMCopyData); message WM_COPYDATA; //Function to receive messages
3) Create a chat form
procedure TForm1.FormShow(Sender: TObject);
var
CreateChatForm: TCreateChatForm;
begin
FChatFormLib := Loadlibrary('UDSClientLib.dll');
if FChatFormLib <> 0 then
begin
@CreateChatForm := GetProcAddress(FChatFormLib, 'CreateChatForm');
if @CreateChatForm <> nil then
FChatFormHwnd := CreateChatForm(Self.Handle, PChar('aa'), PChar('aa'),
PChar('TestUser'), True);
end;
end;
4) End of chat form
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
DestoryChatForm: TDestoryChatForm;
begin
if FChatFormLib <> 0 then
begin
@DestoryChatForm := GetProcAddress(FChatFormLib, 'DestoryChatForm');
if @DestoryChatForm <> nil then
DestoryChatForm;
FreeLibrary(FChatFormLib);
end;
end;
4) Send message
procedure TForm1.BitBtn2Click(Sender: TObject);
var
SendMessage: TSendMessage;
begin
if FChatFormLib <> 0 then
begin
@SendMessage := GetProcAddress(FChatFormLib, 'SendMessage');
if @SendMessage <> nil then
begin
if SendMessage(PChar(edId.Text), PChar(meMsg.Lines.Text), rgMsgType.ItemIndex) then //ID, message transmission method (message displayed in the chat window: 0, 1: Program display)
ShowMessage('OK')
else
ShowMessage('False')
end;
end;
end;
5. Receiving a Message: Windows message WM_COPY method used
* Structure of the received message: ID + #1 + Name + #2 + Message
procedure TForm1.WMCopyData(var AMsg: TWMCopyData);
procedure DisplayMsg(AStr: String);
var
i: Integer;
cId, cNm, cMsg: String;
begin
i := Pos(#2, AStr);
if i <= 0 then
Exit;
cId := Copy(AStr, 1, i -1);
cMsg := Copy(AStr, i + 1, Length(AStr));
i := Pos(#1, AStr);
if i <= 0 then
Exit;
cNm := Copy(cId, 1, i -1);
cId := Copy(cId, i + 1, Length(cId));
ShowMessage('ID = ' + cId + #$D#$A +
'Name = ' + cNm + #$D#$A +
'Message = ' + cMsg);
end;
var
PBuff: PChar;
SubStr: string;
begin
PBuff := StrALloc(AMsg.CopyDataStruct.cbData);
try
StrCopy(PBuff, AMsg.CopyDataStruct.lpData);
SubStr := Trim(PBuff);
if AMsg.CopyDataStruct.dwData = $0717 then
DisplayMsg(SubStr);
finally
StrDispose(PBuff);
end;
inherited;
end;