PB发送和接收消息send SendMessage
1.用PB自带的SEND函数发送消息 传字符:Send(Handle(w_main),1600,0,'dfdfd') 传LONG:Send(Handle(w_main),1600,0,123)
2.用API发送LONG类型消息,申明:
Function long SendMessage(long hwnd,long wMsg,long wParam,long lParam) Library "user32.dll" Alias for "SendMessageA"
发送:SendMessage(Handle(w_main),1600,0,123)
接收方法:
Other事件代码:
if message.number=1600 then
string ls_tmp
ls_tmp=string(message.LongParm)
messagebox("",ls_tmp)
end if
3.用API发送string类型消息,申明:
Function long SendMessage(long hwnd,long wMsg,long wParam,string lParam) Library "user32.dll" Alias for "SendMessageA"
发送:SendMessage(Handle(w_main),1600,0,'123')
接收方法:
Other事件代码:
if message.number=1600 then
string ls_tmp
ls_tmp=string(message.LongParm,'address') //注意这里接收字符的方法
messagebox("",ls_tmp)
end if
******************
DELPHI中给PB窗口发消息,用函数 SendMessage 默认的不能发STRING 类型,必须自己申明一下函数:
function SendMessageAA(hWnd: HWND; Msg: UINT; wParam: WPARAM; lParam: string): LRESULT; stdcall; external 'user32.dll' name 'SendMessageA';
发送代码:
AData := 'ABC';
SendMessageAA(FHandle,WM_NETWORKMSG,0,AData);
搞了很久,才弄出来,和大家分享一下这个发送消息的方法。
*******************
另一个接收消息的方法
申明:
function long GlobalGetAtomName(long ATOM,ref string lpBuffer,integer nSize) Library "kernel32.dll" Alias for "GlobalGetAtomNameA"
function long GlobalDeleteAtom(long ATOM) Library "kernel32.dll"
other事件调用:
if message.number=1600 then
string ls_tmp
long ll_return
ls_tmp=space(50)
ll_return=GlobalGetAtomName(message.LongParm,ls_tmp,50)
GlobalDeleteAtom(message.LongParm)
messagebox("",ls_tmp)
end if