ViSiToR
Silver Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору sproxy 09:53 22-07-2008 Цитата: как передать одному скрипту autoit инфо из другого autoit? | Уже приводил этот(?) пример вроде... нужно бы в шапку его: Код: #NoTrayIcon #include <GuiConstants.au3> ; RegisterScriptMsg("SendMessage Test", $CmdLineRaw) $Gui = GUICreate("SendMessage Test") GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 Exit EndSwitch WEnd Func Main_Msg_Function($vsMsg) MsgBox(0, "", "Recieved message:" & @LF & @LF & $vsMsg) ;Exit EndFunc ;===================================== Func RegisterScriptMsg($sTitle, $vMsg) Local $OccurName = StringReplace(@ScriptFullPath, "\", "") Local $ERROR_ALREADY_EXISTS = 183 Local $ihWnd = WinGetHandle($sTitle) Local $hDll = DllCall("kernel32.dll", "int", "CreateMutex", "int", 0, "long", 1, "str", $OccurName) Local $iLastError = DllCall("kernel32.dll", "int", "GetLastError") If $iLastError[0] = $ERROR_ALREADY_EXISTS Then _AU3COM_SendData($vMsg, $ihWnd) Exit Else Local Const $WM_COPYDATA = 0x4A GUIRegisterMsg($WM_COPYDATA, "_GUIRegisterMsgProc") EndIf EndFunc Func _GUIRegisterMsgProc($hWnd, $MsgID, $WParam, $LParam) Local Const $WM_COPYDATA = 0x4A If $MsgID = $WM_COPYDATA Then Local $vsMsg = _AU3COM_RecvData($LParam) Local $MSGRECVD = DllStructGetData($vsMsg, 1) ;Here is go whatever we need to do with the recieved string ($MSGRECVD) Call("Main_Msg_Function", $MSGRECVD) EndIf EndFunc Func _AU3COM_SendData($InfoToSend, $RecvWinHandle) Local Const $WM_COPYDATA = 0x4A Local $StructDef_COPYDATA = "dword var1;dword var2;ptr var3" Local $CDString = DllStructCreate("char var1[256];char var2[256]") ;the array to hold the string we are sending DllStructSetData($CDString, 1, $InfoToSend) Local $pCDString = DllStructGetPtr($CDString) ;the pointer to the string Local $vs_cds = DllStructCreate($StructDef_COPYDATA);create the message struct DllStructSetData($vs_cds, "var1", 0) ;0 here indicates to the receiving program that we are sending a string DllStructSetData($vs_cds, "var2", String(StringLen($InfoToSend) + 1));tell the receiver the length of the string DllStructSetData($vs_cds, "var3", $pCDString) ;the pointer to the string Local $pStruct = DllStructGetPtr($vs_cds) DllCall("user32.dll", "long", "SendMessage", "hwnd", $RecvWinHandle, "int", $WM_COPYDATA, "int", 0, "int", $pStruct) $vs_cds = 0 ;free the struct $CDString = 0 ;free the struct Return 1 EndFunc Func _AU3COM_RecvData($COM_LParam) ; $COM_LParam = Poiter to a COPYDATA Struct Local $STRUCTDEF_AU3MESSAGE = "char var1[256];int" Local $StructDef_COPYDATA = "dword var1;dword var2;ptr var3" Local $vs_cds = DllStructCreate($StructDef_COPYDATA, $COM_LParam) ; Member No. 3 of COPYDATA Struct (PVOID lpData;) = Pointer to Costum Struct Local $vs_msg = DllStructCreate($STRUCTDEF_AU3MESSAGE, DllStructGetData($vs_cds, 3)) Return $vs_msg EndFunc | Вот скрипт для проверки: Код: Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & @ScriptDir & '\Register Script Msg.au3" /Param') | Как видно, интеракция происходит посредствам командной строки. Добавлено: Ещё вариант, более продвинуты (в стиле UDF): UDF - «AU3_INTERACT.au3»: Код: #include-once If Not IsDeclared("WM_USER") Then Assign("WM_USER", 0x0400, 1) Global $vINTERACT_Msg = -1 Global $aMAIN_FUNCTIONS = -1 Global $h_MAIN_INTERACT_GUI = 0 Global $ah_INTERACT_TIMER[2] = [-1, -1] Func OnAutoItExit() If $ah_INTERACT_TIMER[0] <> -1 Then _TimerStop($ah_INTERACT_TIMER[0], $ah_INTERACT_TIMER[1]) EndFunc Func _Interaction_Handler($hWnd, $MsgID, $WParam, $LParam) If $vINTERACT_Msg = -1 Then Return For $i = 0 To UBound($aMAIN_FUNCTIONS)-1 If $aMAIN_FUNCTIONS[$i][0] = $vINTERACT_Msg Then $vINTERACT_Msg = -1 Call($aMAIN_FUNCTIONS[$i][1], $aMAIN_FUNCTIONS[$i][2]) If @error Then Call($aMAIN_FUNCTIONS[$i][1]) ExitLoop EndIf Next $vINTERACT_Msg = -1 EndFunc Func _AutoItSetInteraction($hWnd=0, $MsgID=0, $WParam=0, $LParam=0) If Not IsHWnd($hWnd) Then If Not IsArray($MsgID) Then GUIRegisterMsg($WM_USER, "") If IsHWnd($h_MAIN_INTERACT_GUI) Then GUIDelete($h_MAIN_INTERACT_GUI) _TimerStop($ah_INTERACT_TIMER[0], $ah_INTERACT_TIMER[1]) Return EndIf $ah_INTERACT_TIMER = _TimerStart("_Interaction_Handler", 10) $aMAIN_FUNCTIONS = $MsgID $h_MAIN_INTERACT_GUI = GUICreate($hWnd) GUIRegisterMsg($WM_USER, "_AutoItSetInteraction") Return EndIf $vINTERACT_Msg = BitAND($LParam, 0xFFFF) EndFunc Func _TimerStart($sFunction, $iTime=250) Local $hCallBack = DllCallbackRegister($sFunction, "none", "hwnd;int;int;dword") Local $aDll = DllCall("user32.dll", "int", "SetTimer", _ "hwnd", 0, _ "int", TimerInit(), _ "int", $iTime, _ "ptr", DllCallbackGetPtr($hCallBack)) Local $aRet[2] = [$hCallBack, $aDll[0]] Return $aRet EndFunc Func _TimerStop($hCallBack, $hTimer) DllCallBackFree($hCallBack) Local $aRet = DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "int", $hTimer) Return $aRet[0] EndFunc | Получатель - «Reciever.au3»: Код: #include <GuiConstantsEx.au3> #include <WindowsConstants.au3> #include <AU3_INTERACT.au3> ; #Region _AutoItSetInteraction() Part Dim $aFunctions[3][3] $aFunctions[0][0] = 1001 $aFunctions[0][1] = "My_Function_1" $aFunctions[0][2] = "Some Param1" $aFunctions[1][0] = 1002 $aFunctions[1][1] = "My_Function_2" $aFunctions[1][2] = "This is parameter for My_Function_2" $aFunctions[2][0] = 1003 $aFunctions[2][1] = "My_Function_3" $aFunctions[2][2] = "Well, you get the picture " _AutoItSetInteraction("_MYAPP_", $aFunctions) #EndRegion _AutoItSetInteraction() Part ; $hGUI = GUICreate("_AutoItSetInteraction Demo", 400, 200, -1, -1, -1, $WS_EX_TOPMOST) $Edit = GUICtrlCreateEdit("", 10, 10, 380, 180) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func My_Function_1($vParam) GUICtrlSetData($Edit, "Function 1 Fired, with param: " & $vParam & @CRLF, 1) MsgBox(262144+64, "", "Function 1 Fired!") EndFunc Func My_Function_2($vParam) GUICtrlSetData($Edit, "Function 2 Fired, with param: " & $vParam & @CRLF, 1) MsgBox(262144+64, "", "Function 2 Fired!") EndFunc Func My_Function_3($vParam) GUICtrlSetData($Edit, "Function 3 Fired, with param: " & $vParam & @CRLF, 1) MsgBox(262144+64, "", "Function 3 Fired!") EndFunc | Отправитель - «Sender.au3»: Код: #include <SendMessage.au3> Global Const $WM_AU3_USR = 0x0400 ;$WM_USER $hWnd = WinGetHandle("[CLASS:AutoIt v3 GUI;TITLE:_MYAPP_]") _SendMessage($hWnd, $WM_AU3_USR, 0, 1001) Sleep(1500) _SendMessage($hWnd, $WM_AU3_USR, 0, 1002) Sleep(1500) _SendMessage($hWnd, $WM_AU3_USR, 0, 1003) |
---------- ViSiToR a.k.a CreatoR CreatoR это не ник, CreatoR это стиль жизни! |
| Всего записей: 3251 | Зарегистр. 01-04-2006 | Отправлено: 15:18 22-07-2008 | Исправлено: ViSiToR, 17:04 23-07-2008 |
|