我不知道你乱码是怎么产生的,WM_COPYDATA函数也是比较可靠的,还是那句话,有问题很正常,问题是怎么产生的,自己多思考,别人只能给你抛砖引玉,不会给你具体的代码实现
#include <GuiEdit.au3>
Global $My_Hwnd = GUICreate("WM_COPYDATA接收", 300, 600, @DesktopWidth / 2 - 300, Default, Default, 0x00000008)
$ssss= GUICtrlCreateEdit('', 5,5,280,400)
GUIRegisterMsg(0x004A, "WM_COPYDATA")
GUISetState()
Run(StringFormat('"%s" "%s" "%s"',@AutoItExe,@ScriptDir & '\WM_COPYDATA发送.au3',String($My_Hwnd)))
Do
Until GUIGetMsg() = -3
Func WM_COPYDATA($hWnd, $Msg, $wParam, $lParam)
#forceref $hWnd, $Msg, $wParam, $lParam
Local $COPYDATA, $tMyData, $MyData
$COPYDATA = DllStructCreate("ptr;dword;ptr", $lParam)
$tMyData = DllStructCreate("byte[" & DllStructGetData($COPYDATA, 2) & "]", DllStructGetData($COPYDATA, 3))
$MyData = BinaryToString(DllStructGetData($tMyData, 1), 4)
_GUICtrlEdit_AppendText($ssss, $MyData & @CRLF)
Return
EndFunc ;==>WM_COPYDATA
#include <GuiEdit.au3>
Global $hWndTarget
Global $WM_COPYDATA = 0x004A
If $cmdline[0] = 1 Then
$hWndTarget = HWnd($cmdline[1])
Else
Exit MsgBox(0,1,'请先运行接收端')
EndIf
Global $My_Hwnd = GUICreate("WM_COPYDATA发送", 300, 600, @DesktopWidth / 2 + 5, Default, Default, 0x00000008)
$ssss= GUICtrlCreateEdit('', 5,5,280,400)
$bbbb = GUICtrlCreateButton('请直接点击', 10, 450, 100, 30)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $bbbb
For $i = 129 To 131
For $j = 64 To 254
Local $code = Hex($i, 2) & Hex($j, 2)
Local $str = BinaryToString('0x' & $code)
If $j <> 127 Then _GUICtrlEdit_AppendText($ssss, '"' & $str & '","' & $code & '"')
SendData($hWndTarget, '"' & $str & '","' & $code & '"')
Next
If $i <> 87 Then _GUICtrlEdit_AppendText($ssss, @CRLF)
SendData($hWndTarget, @CRLF)
Next
EndSwitch
WEnd
Func SendData($hWndTarget, $sData)
Local $msg = StringToBinary($sData, 4)
Local $MyData = DllStructCreate("byte[" & BinaryLen($msg) & "]")
Local $COPYDATA = DllStructCreate("ptr;dword;ptr")
DllStructSetData($MyData, 1, $msg)
DllStructSetData($COPYDATA, 1, 0)
DllStructSetData($COPYDATA, 2, DllStructGetSize($MyData))
DllStructSetData($COPYDATA, 3, DllStructGetPtr($MyData))
Local $aTmp = DllCall("user32.dll", "int", "SendMessageTimeout", "hwnd", $hWndTarget, "int", $WM_COPYDATA _ ; WM_COPYDATA
, "int", 0, "ptr", DllStructGetPtr($COPYDATA), "int", 0, "int", 1000, "long*", 0)
EndFunc ;==>SendSciTE_Command
|