本帖最后由 风行者 于 2013-11-21 22:10 编辑
写个小例子
发送消息A窗口#include <SendMessage.au3>
Global Const $WM_COPYDATA = 0x4A
$Form1 = GUICreate("A窗口")
$button = GUICtrlCreateButton("发送",100,100,100,30)
GUISetState()
While 1
Local $msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $button
Local $hwnd = WinGetHandle("B窗口")
_SendCopyData($hwnd,"发送的消息send!")
EndSwitch
WEnd
Func _SendCopyData($hwnd, $data) ;发送消息
Local $len = BinaryLen(StringToBinary($data))*2
Local $tagCOPYDATASTRUCT = DllStructCreate( _
"DWORD dwData;" & _
"DWORD cbData;" & _
"ptr lpData;")
Local $lpdata = DllStructCreate("wchar lpData["&$len&"]")
DllStructSetData($lpdata,1,$data)
DllStructSetData($tagCOPYDATASTRUCT,1,0)
DllStructSetData($tagCOPYDATASTRUCT,2,$len)
DllStructSetData($tagCOPYDATASTRUCT,3,DllStructGetPtr($lpdata))
_SendMessage($hwnd, $WM_COPYDATA, 0,DllStructGetPtr($tagCOPYDATASTRUCT))
EndFunc ;==>_SendCopyData
接收消息B窗口#include <GUIConstants.au3>
Global Const $WM_COPYDATA = 0x4A
GUICreate('B窗口')
GUISetState()
GUIRegisterMsg($WM_COPYDATA, "WM_COPYDATA")
Do
Until GUIGetMsg()=-3
Func WM_COPYDATA($hWnd, $wMsg, $wParam, $wlParam)
Local $SSS = "DWORD dwData;DWORD cbData;ptr lpData;"
Local $struct = DllStructCreate($SSS, $wlParam)
Local $CopyData = DllStructGetData($struct, 3) ;第三个元素是数据的指针
Local $len = DllStructGetData($struct,2)
Local $copy = "wchar str["&$len&"]" ;发送内容的数据结构
Local $data = DllStructCreate($copy, $CopyData)
Local $str = DllStructGetData($data,"str") ;返回的内容
MsgBox(64,"接收到的消息",$str)
EndFunc ;==>WM_COPYDATA
|