PB發送和接收消息send SendMessage函數
1.用PB自帶的SEND函數發送消息 傳字符:Send(Handle(w_main),1600,0,'dfdfd') 傳LONG:Send(Handle(w_main),1600,0,123)spa
2.用API發送LONG類型消息,申明:事件
Function long SendMessage(long hwnd,long wMsg,long wParam,long lParam) Library "user32.dll" Alias for "SendMessageA"get
發送:SendMessage(Handle(w_main),1600,0,123)string
接收方法:io
Other事件代碼:function
if message.number=1600 then
string ls_tmp
ls_tmp=string(message.LongParm)
messagebox("",ls_tmp)
end ifclass
3.用API發送string類型消息,申明:channel
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