[R] Envoie de message entre programmes pour synchronisation
Posté : mar. 10 août 2021 16:03
par Exter76
Bonjour à tous !
J'aurai une petite question, je travail sur un petit projet et mon idée serai comme son nom l'indique,
de pouvoir envoyer différent message entre les programmes pour que ceux-ci puisse se synchroniser.
Je vais vous donner un petit exemple pour vous donner une idée plus clair:
Programme 1 et 2 écrivent chacun un mail, Statuts dans leur l'edit: "Mail en cours"
une fois le mail envoyer statuts: "Envoyer"
Programme 3 et 4 une fois que le statuts des 1 et 2 est écris: "Envoyer"
ils vont vérifier l'adresse mail que je leur ai fournis, attendre la réception du mail pour y répondre et transféré un message et au programmes 4 et 5 et ainsi de suite.
Je me doute qu'il y a beaucoup plus simple a faire,
mais se qui m'intéresse dans ce cas c'est plutôt la communication entre plusieurs programme via une seul interface.
J'ai trouver différent script qui m'aiderait a faire cela, mais il interagissent entre différents GUI alors que j'aimerai pouvoir n'en utiliser qu'un seul.
Exemple de se que j'ai pu trouver:
Et voilà le genre d'interface que je souhaite utiliser:
Les Combo de mon interface me serviront a sélectionner quel programme je souhaite utiliser et le bouton Start pour l'exécuter, jusque là tout va bien.
Les différents Edit me servirons à indiquer le statuts du programme en cours:
"En cours" - "A l'arrêt" - "Exécute l'étape 1" - "Exécute l'étape 2" ect...
Et là est mon premier soucis, dois-je utiliser un Edit sachant que les programmes devront principalement lire les derniers messages et j'ai peur que cela ne risque de créer des confusion, a moins qu'il y a un moyen d'avoir une lecture uniquement du dernier message ?
Ou alors je vais devoir utiliser autre chose ?
Et là deuxième soucis que je rencontre,
Comment est-ce que je pourrais indiquer au programme 2 ou 3 de lire le dernier message de l'edit du programme 1 ?
Se serait principalement attendre le "Envoyer" du programme 1 pour exécuter son action.
C'est uniquement pour "la gloire", je me répète mais je sais qu'il y a plus simple, c'est justement le fait de pouvoir faire une synchronisation des programmes via l'interface qui m'intéresse
Dans l'attente de votre aide, Merci d'avance
J'aurai une petite question, je travail sur un petit projet et mon idée serai comme son nom l'indique,
de pouvoir envoyer différent message entre les programmes pour que ceux-ci puisse se synchroniser.
Je vais vous donner un petit exemple pour vous donner une idée plus clair:
Programme 1 et 2 écrivent chacun un mail, Statuts dans leur l'edit: "Mail en cours"
une fois le mail envoyer statuts: "Envoyer"
Programme 3 et 4 une fois que le statuts des 1 et 2 est écris: "Envoyer"
ils vont vérifier l'adresse mail que je leur ai fournis, attendre la réception du mail pour y répondre et transféré un message et au programmes 4 et 5 et ainsi de suite.
Je me doute qu'il y a beaucoup plus simple a faire,
mais se qui m'intéresse dans ce cas c'est plutôt la communication entre plusieurs programme via une seul interface.
J'ai trouver différent script qui m'aiderait a faire cela, mais il interagissent entre différents GUI alors que j'aimerai pouvoir n'en utiliser qu'un seul.
Exemple de se que j'ai pu trouver:
► Afficher le texte
AppInteract:
Script1:
Script2:
► Afficher le texte
#include-once
#include <APIConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>
#include <WinAPISysWin.au3>
#CS History:
v0.5
* Removed 1024 bytes limitation (thanks to Danyfirex).
* Now the return data can be any type of data except 3D (or higher) arrays, objects and structures.
* Changed return values on @error in _AppInteract_Send.
* Better error handling.
v0.4
+ Added x64 support.
+ Added more examples (Thanks to Vanguger for Example #3).
* Now sent data can be any type of data except 3D (or higher) arrays, objects and structures.
* Now the option to return data back from the receiver is more reliable.
* _AppInteract_Send now returns only string data type (up to 1024 bytes) from the receiver.
- Removed $sRetAppName parameter from _AppInteract_Send function due to change of return method.
v0.3
+ Added option to return from the receiver back to the sent process.
+ For the return option, added optional parameter $sRetAppName to _AppInteract_Send function.
* Minor corrections.
+ Added examples to show how the _AppInteract_Send can get the return.
v0.2
* Better interaction in both ways.
+ Added $sCmdLine optional parameter to check executable command line.
* Examples changed.
v0.1
* First public version.
#CE
; #INDEX# =======================================================================================================================
; Title .........: AppInteract UDF
; AutoIt Version : 3.3.14.5
; Description ...: Allows to interact between two processes.
; Note(s) .......: * This UDF registers $WM_COPYDATA, if you or other UDF uses this message,
; __AppInteract_WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam) should be called from that other message function.
; * Do not use any delay functions inside the receiver function, the return must be as soon as possible.
; Author(s) .....: Copyright © 2020 G.Sandler. All rights reserved.
; Dll ...........: user32.dll
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _AppInteract_SetReceiver
; _AppInteract_Send
; ===============================================================================================================================
Global Const $tagCOPYDATASTRUCT = 'ulong_ptr dwData;dword cbData;ptr lpData'
Global Const $APPINTRCT_VRNT_ROW_SEP = '~APPINTRCT_UNIQUE_ROW_SEPARATOR~'
Global Const $APPINTRCT_VRNT_COL_SEP = '~APPINTRCT_UNIQUE_COL_SEPARATOR~'
Global Const $APPINTRCT_VAR_TYPES = __AppInteract_Variant_GetTypes()
Global $APPINTRCT_HWND
Global $APPINTRCT_RECEIVER
; #FUNCTION# ====================================================================================================================
; Name ..........: _AppInteract_SetReceiver
; Description ...: Sets receiver for current script.
; Syntax ........: _AppInteract_SetReceiver($sAppName, $sFuncName)
; Parameters ....: $sAppName - Your application Unique name.
; $sFuncName - Function name to call once the data received.
; This function accepts only one parameter with the received data.
; Return values .: None
; Author ........: G.Sandler
; Modified ......:
; Remarks .......: * Do not use any delay functions inside the $sFuncName function, the return must be as soon as possible.
; * If #RequireAdmin used in the receiver, it should be used in the sender as well!
; Related .......: _AppInteract_Send
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AppInteract_SetReceiver($sAppName, $sFuncName)
If Not IsHWnd($APPINTRCT_HWND) Then
$APPINTRCT_HWND = GUICreate($sAppName)
GUIRegisterMsg($WM_COPYDATA, '__AppInteract_WM_COPYDATA')
EndIf
$APPINTRCT_RECEIVER = $sFuncName
EndFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _AppInteract_Send
; Description ...: Sends data to the receiver.
; Syntax ........: _AppInteract_Send($sAppName, $vData[, $sPath = '' [, $sCmdLine = '']])
; Parameters ....: $sAppName - Application Unique name that receives the data.
; Should be the same as used in the _AppInteract_SetReceiver function.
; $vData - Data to send, can be any type of data except 3D (or higher) arrays, objects and structures.
; $sPath - [optional] Path to script executable to check.
; Default is '' - do not check application path (less reliable).
; $sCmdLine - [optional] Executable command line to check (partial check).
; Default is '' - do not check for command line (less reliable).
; Return values .: Success: Returns the data from the receiver.
; Failure: Returns 0 and sets @error flag to non-zero:
; 1 - Window handle of the receiver not found.
; 2 - Unable to send data (SendMessage error).
; -1 - $vData is not supported data type.
; Author ........: G.Sandler
; Modified ......:
; Remarks .......: If #RequireAdmin used in the receiver, it should be used in the sender as well!
; Related .......: _AppInteract_SetReceiver
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AppInteract_Send($sAppName, $vData, $sPath = '', $sCmdLine = '')
If Not __AppInteract_Variant_IsSupportedType($vData) Then
Return SetError(-1, 0, 0)
EndIf
Local $hWnd, $tPtr, $tData, $tCopyData, $aRet, $pData, $tSize, $stStr
$hWnd = __AppInteract_GetHwnd($sAppName, $sPath, $sCmdLine)
If @error Then
Return SetError(1, 0, 0)
EndIf
$vData = __AppInteract_Variant_Pack($vData)
$tPtr = DllStructCreate('ptr pData') ;Pointer for reading vRet Value
$tData = DllStructCreate('Ptr pReturn;long iPID;wchar sData[' & (StringLen($vData) + 1) & ']')
DllStructSetData($tData, 'pReturn', DllStructGetPtr($tPtr))
DllStructSetData($tData, 'iPID', @AutoItPID) ;Pid for write memory
DllStructSetData($tData, 'sData', $vData) ;Data to Send
$tCopyData = DllStructCreate($tagCOPYDATASTRUCT)
DllStructSetData($tCopyData, 'cbData', DllStructGetSize($tData))
DllStructSetData($tCopyData, 'lpData', DllStructGetPtr($tData))
$aRet = DllCall('user32.dll', 'lresult', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($tCopyData))
If @error Then
Return SetError(2, 0, 0)
EndIf
$pData = Ptr(DllStructGetData($tPtr, 'pData'))
$tSize = __AppInteract_ReadProcessMemory(WinGetProcess($hWnd), $pData, 'long iSize')
$stStr = __AppInteract_ReadProcessMemory(WinGetProcess($hWnd), $pData + 4, 'wchar sStr[' & DllStructGetData($tSize, 'iSize') & ']')
Return __AppInteract_Variant_UnPack(DllStructGetData($stStr, 'sStr'))
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_GetHwnd
; Description ...: Gets receiver window.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_GetHwnd($sAppName, $sPath, $sCmdLine)
Local $aWinList, $iPID, $bVisible, $bPath, $bCmdLine, $hWnd = 0
Local $sTitle = '[CLASS:AutoIt v3 GUI;TITLE:' & $sAppName & ']'
If IsHWnd($sAppName) Then
$hWnd = $sAppName
Else
$aWinList = WinList($sTitle)
For $i = 1 To UBound($aWinList) - 1
$iPID = WinGetProcess($aWinList[$i][1])
$bVisible = (BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_VISIBLE) = $WIN_STATE_VISIBLE)
$bPath = (StringStripWS($sPath, 8) = '' Or $sPath = _WinAPI_GetProcessFileName($iPID))
$bCmdLine = (StringStripWS($sCmdLine, 8) = '' Or StringInStr(_WinAPI_GetProcessCommandLine($iPID), $sCmdLine))
If (@AutoItPID <> $iPID) And Not $bVisible And $bPath And $bCmdLine Then
$hWnd = $aWinList[$i][1]
ExitLoop
EndIf
Next
EndIf
If Not $hWnd Then
$hWnd = WinGetHandle($sTitle)
EndIf
Return SetError((IsHWnd($hWnd) ? 0 : 1), 0, $hWnd)
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_ReadProcessMemory
; Description ...: Reads process memory by pointer and returns structure.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_ReadProcessMemory($iPID, $pPointer, $sStructTag)
Local $hProcess, $stStruct, $iSize, $pStruct, $iRead
$hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID)
If @error Then Return SetError(@error, 1, 0)
$stStruct = DllStructCreate($sStructTag)
$iSize = DllStructGetSize($stStruct)
$pStruct = DllStructGetPtr($stStruct)
_WinAPI_ReadProcessMemory($hProcess, $pPointer, $pStruct, $iSize, $iRead)
_WinAPI_CloseHandle($hProcess)
Return SetError(@error, $iRead, $stStruct)
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_WriteProcessMemoryPtr
; Description ...: Writes to process memory by pointer.
; Author ........: Danyfirex (mod. by G.Sandler)
; ===============================================================================================================================
Func __AppInteract_WriteProcessMemoryPtr($iPID, $pPointer, $ptPtr)
Local $hProcess, $stData, $iSize, $pData, $bWrite, $iWriten
$hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID)
If @error Then Return SetError(@error, 1, 0)
$stData = DllStructCreate('ptr pData')
$iSize = DllStructGetSize($stData)
$pData = DllStructGetPtr($stData)
DllStructSetData($stData, 'pData', $ptPtr)
$bWrite = _WinAPI_WriteProcessMemory($hProcess, $pPointer, $pData, $iSize, $iWriten)
_WinAPI_CloseHandle($hProcess)
Return SetError(@error, $iWriten, $bWrite)
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_WM_COPYDATA
; Description ...: Interaction handler.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
If $hWnd <> $APPINTRCT_HWND Then
Return 'GUI_RUNDEFMSG'
EndIf
Local $tCopyData, $tData, $sStr, $vRet, $iLen
Local Static $stStr
$tCopyData = DllStructCreate($tagCOPYDATASTRUCT, $lParam)
$tData = DllStructCreate('Ptr pReturn;long iPID;wchar sData[' & (DllStructGetData($tCopyData, 'cbData') - (@AutoItX64 ? 12 : 8)) & ']', DllStructGetData($tCopyData, 'lpData'))
$sStr = __AppInteract_Variant_UnPack(DllStructGetData($tData, 'sData'))
$vRet = Call($APPINTRCT_RECEIVER, $sStr)
$vRet = __AppInteract_Variant_Pack($vRet)
If @error Then
Return 'GUI_RUNDEFMSG'
EndIf
$iLen = (StringLen($vRet) + 1)
$stStr = DllStructCreate('long iSize;wchar sStr[' & $iLen & ']')
DllStructSetData($stStr, 'iSize', $iLen)
DllStructSetData($stStr, 'sStr', $vRet)
Return __AppInteract_WriteProcessMemoryPtr(DllStructGetData($tData, 'iPID'), DllStructGetData($tData, 'pReturn'), DllStructGetPtr($stStr))
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_Pack
; Description ...: Pack variable to string.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_Pack($vData)
If Not __AppInteract_Variant_IsSupportedType($vData) Then
Return SetError(1, 0, $vData)
EndIf
Local $sVarType = VarGetType($vData)
If $sVarType <> 'Array' Then
If $sVarType = 'Ptr' And HWnd($vData) Then
Return '[HWnd]' & String($vData)
EndIf
If $sVarType = 'Function' Or $sVarType = 'UserFunction' Then
$vData = FuncName($vData)
EndIf
Return '[' & $sVarType & ']' & String($vData)
EndIf
Local $sRet = ''
Local $iDim = UBound($vData, $UBOUND_DIMENSIONS)
Switch $iDim
Case 1
For $iRow = 0 To UBound($vData, $UBOUND_ROWS) - 1
$sRet &= ($sRet ? $APPINTRCT_VRNT_ROW_SEP : '') & __AppInteract_Variant_Pack($vData[$iRow])
Next
Case 2
For $iRow = 0 To UBound($vData, $UBOUND_ROWS) - 1
$sRet &= ($iRow ? $APPINTRCT_VRNT_COL_SEP : '')
For $iCol = 0 To UBound($vData, $UBOUND_COLUMNS) - 1
$sRet &= ($iCol ? $APPINTRCT_VRNT_ROW_SEP : '') & __AppInteract_Variant_Pack($vData[$iRow][$iCol])
Next
Next
EndSwitch
Return '[Array,' & $iDim & ']' & $sRet
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_UnPack
; Description ...: UnPack string to variable (preserving data types).
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_UnPack($sData)
If Not __AppInteract_Variant_IsSupportedType($sData) Then
Return SetError(1, 0, $sData)
EndIf
Local $aData = StringRegExp($sData, '(?s)^\[((?:' & $APPINTRCT_VAR_TYPES & ')(?:,\d)?)\](.*)$', 1)
If UBound($aData) < 2 Then
Return $sData
EndIf
Local $vRet = $aData[1]
Local $iDim = Int(StringRegExpReplace($aData[0], '^.*,(\d)$', '\1'))
If $iDim Then
$aData[0] = StringTrimRight($aData[0], 2) ;Remove array dimension
EndIf
Switch $aData[0]
Case 'Int32', 'Int64', 'Double'
$vRet = Number($aData[1])
Case 'Bool'
$vRet = ($aData[1] = 'True')
Case 'String', 'Binary', 'Ptr', 'HWnd'
Local $hFunc = Execute($aData[0])
$vRet = $hFunc($aData[1])
Case 'Keyword'
$vRet = ($aData[1] = 'Default' ? Default : Null)
Case 'Function', 'UserFunction'
$vRet = Execute($aData[1])
Case 'Array'
Switch $iDim
Case 1
$vRet = StringSplit($aData[1], $APPINTRCT_VRNT_ROW_SEP, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
For $i = 0 To UBound($vRet, $UBOUND_ROWS) - 1
$vRet[$i] = __AppInteract_Variant_UnPack($vRet[$i])
Next
Case 2
Local $aRows = StringSplit($aData[1], $APPINTRCT_VRNT_COL_SEP, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
Local $iRows = UBound($aRows, $UBOUND_ROWS)
Local $iCols
Dim $vRet[$iRows][1]
For $iRow = 0 To $iRows - 1
$aCols = StringSplit($aRows[$iRow], $APPINTRCT_VRNT_ROW_SEP, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
$iCols = UBound($aCols, $UBOUND_ROWS)
ReDim $vRet[$iRows][$iCols]
For $iCol = 0 To $iCols - 1
$vRet[$iRow][$iCol] = __AppInteract_Variant_UnPack($aCols[$iCol])
Next
Next
EndSwitch
EndSwitch
Return $vRet
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_IsSupportedType
; Description ...: Checks if a given data is supported data type.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_IsSupportedType($vData)
Switch VarGetType($vData)
Case 'Array'
If UBound($vData, $UBOUND_DIMENSIONS) > 2 Then
Return False
EndIf
Case 'Object', 'DllStruct'
Return False
EndSwitch
Return True
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_GetTypes
; Description ...: Gets all(?) AutoIt variable types.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_GetTypes($bArr = False)
Local $aVars[] = _
[ _
StringSplit('', ''), Binary('0'), True, Ptr(-1), WinGetHandle(''), 1, DllStructSetData(DllStructCreate('int64'), 1, 1), 2.0, _
ObjCreate('Scripting.Dictionary'), 'a', DllStructCreate('int'), Default, Int, __AppInteract_Variant_GetTypes _
]
Local $sType, $sTypes = ''
For $i = 0 To UBound($aVars) - 1
$sType = VarGetType($aVars[$i])
$sTypes &= ($sTypes ? '|' : '') & (($sType = 'Ptr' And HWnd($aVars[$i])) ? 'HWnd' : $sType)
$aVars[$i] = 0
Next
If $bArr Then
$sTypes = StringSplit($sTypes, '|')
EndIf
Return $sTypes
EndFunc
#include <APIConstants.au3>
#include <WinAPIProc.au3>
#include <WinAPIMem.au3>
#include <WinAPISysWin.au3>
#CS History:
v0.5
* Removed 1024 bytes limitation (thanks to Danyfirex).
* Now the return data can be any type of data except 3D (or higher) arrays, objects and structures.
* Changed return values on @error in _AppInteract_Send.
* Better error handling.
v0.4
+ Added x64 support.
+ Added more examples (Thanks to Vanguger for Example #3).
* Now sent data can be any type of data except 3D (or higher) arrays, objects and structures.
* Now the option to return data back from the receiver is more reliable.
* _AppInteract_Send now returns only string data type (up to 1024 bytes) from the receiver.
- Removed $sRetAppName parameter from _AppInteract_Send function due to change of return method.
v0.3
+ Added option to return from the receiver back to the sent process.
+ For the return option, added optional parameter $sRetAppName to _AppInteract_Send function.
* Minor corrections.
+ Added examples to show how the _AppInteract_Send can get the return.
v0.2
* Better interaction in both ways.
+ Added $sCmdLine optional parameter to check executable command line.
* Examples changed.
v0.1
* First public version.
#CE
; #INDEX# =======================================================================================================================
; Title .........: AppInteract UDF
; AutoIt Version : 3.3.14.5
; Description ...: Allows to interact between two processes.
; Note(s) .......: * This UDF registers $WM_COPYDATA, if you or other UDF uses this message,
; __AppInteract_WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam) should be called from that other message function.
; * Do not use any delay functions inside the receiver function, the return must be as soon as possible.
; Author(s) .....: Copyright © 2020 G.Sandler. All rights reserved.
; Dll ...........: user32.dll
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
; _AppInteract_SetReceiver
; _AppInteract_Send
; ===============================================================================================================================
Global Const $tagCOPYDATASTRUCT = 'ulong_ptr dwData;dword cbData;ptr lpData'
Global Const $APPINTRCT_VRNT_ROW_SEP = '~APPINTRCT_UNIQUE_ROW_SEPARATOR~'
Global Const $APPINTRCT_VRNT_COL_SEP = '~APPINTRCT_UNIQUE_COL_SEPARATOR~'
Global Const $APPINTRCT_VAR_TYPES = __AppInteract_Variant_GetTypes()
Global $APPINTRCT_HWND
Global $APPINTRCT_RECEIVER
; #FUNCTION# ====================================================================================================================
; Name ..........: _AppInteract_SetReceiver
; Description ...: Sets receiver for current script.
; Syntax ........: _AppInteract_SetReceiver($sAppName, $sFuncName)
; Parameters ....: $sAppName - Your application Unique name.
; $sFuncName - Function name to call once the data received.
; This function accepts only one parameter with the received data.
; Return values .: None
; Author ........: G.Sandler
; Modified ......:
; Remarks .......: * Do not use any delay functions inside the $sFuncName function, the return must be as soon as possible.
; * If #RequireAdmin used in the receiver, it should be used in the sender as well!
; Related .......: _AppInteract_Send
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AppInteract_SetReceiver($sAppName, $sFuncName)
If Not IsHWnd($APPINTRCT_HWND) Then
$APPINTRCT_HWND = GUICreate($sAppName)
GUIRegisterMsg($WM_COPYDATA, '__AppInteract_WM_COPYDATA')
EndIf
$APPINTRCT_RECEIVER = $sFuncName
EndFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _AppInteract_Send
; Description ...: Sends data to the receiver.
; Syntax ........: _AppInteract_Send($sAppName, $vData[, $sPath = '' [, $sCmdLine = '']])
; Parameters ....: $sAppName - Application Unique name that receives the data.
; Should be the same as used in the _AppInteract_SetReceiver function.
; $vData - Data to send, can be any type of data except 3D (or higher) arrays, objects and structures.
; $sPath - [optional] Path to script executable to check.
; Default is '' - do not check application path (less reliable).
; $sCmdLine - [optional] Executable command line to check (partial check).
; Default is '' - do not check for command line (less reliable).
; Return values .: Success: Returns the data from the receiver.
; Failure: Returns 0 and sets @error flag to non-zero:
; 1 - Window handle of the receiver not found.
; 2 - Unable to send data (SendMessage error).
; -1 - $vData is not supported data type.
; Author ........: G.Sandler
; Modified ......:
; Remarks .......: If #RequireAdmin used in the receiver, it should be used in the sender as well!
; Related .......: _AppInteract_SetReceiver
; Link ..........:
; Example .......: Yes
; ===============================================================================================================================
Func _AppInteract_Send($sAppName, $vData, $sPath = '', $sCmdLine = '')
If Not __AppInteract_Variant_IsSupportedType($vData) Then
Return SetError(-1, 0, 0)
EndIf
Local $hWnd, $tPtr, $tData, $tCopyData, $aRet, $pData, $tSize, $stStr
$hWnd = __AppInteract_GetHwnd($sAppName, $sPath, $sCmdLine)
If @error Then
Return SetError(1, 0, 0)
EndIf
$vData = __AppInteract_Variant_Pack($vData)
$tPtr = DllStructCreate('ptr pData') ;Pointer for reading vRet Value
$tData = DllStructCreate('Ptr pReturn;long iPID;wchar sData[' & (StringLen($vData) + 1) & ']')
DllStructSetData($tData, 'pReturn', DllStructGetPtr($tPtr))
DllStructSetData($tData, 'iPID', @AutoItPID) ;Pid for write memory
DllStructSetData($tData, 'sData', $vData) ;Data to Send
$tCopyData = DllStructCreate($tagCOPYDATASTRUCT)
DllStructSetData($tCopyData, 'cbData', DllStructGetSize($tData))
DllStructSetData($tCopyData, 'lpData', DllStructGetPtr($tData))
$aRet = DllCall('user32.dll', 'lresult', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($tCopyData))
If @error Then
Return SetError(2, 0, 0)
EndIf
$pData = Ptr(DllStructGetData($tPtr, 'pData'))
$tSize = __AppInteract_ReadProcessMemory(WinGetProcess($hWnd), $pData, 'long iSize')
$stStr = __AppInteract_ReadProcessMemory(WinGetProcess($hWnd), $pData + 4, 'wchar sStr[' & DllStructGetData($tSize, 'iSize') & ']')
Return __AppInteract_Variant_UnPack(DllStructGetData($stStr, 'sStr'))
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_GetHwnd
; Description ...: Gets receiver window.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_GetHwnd($sAppName, $sPath, $sCmdLine)
Local $aWinList, $iPID, $bVisible, $bPath, $bCmdLine, $hWnd = 0
Local $sTitle = '[CLASS:AutoIt v3 GUI;TITLE:' & $sAppName & ']'
If IsHWnd($sAppName) Then
$hWnd = $sAppName
Else
$aWinList = WinList($sTitle)
For $i = 1 To UBound($aWinList) - 1
$iPID = WinGetProcess($aWinList[$i][1])
$bVisible = (BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_VISIBLE) = $WIN_STATE_VISIBLE)
$bPath = (StringStripWS($sPath, 8) = '' Or $sPath = _WinAPI_GetProcessFileName($iPID))
$bCmdLine = (StringStripWS($sCmdLine, 8) = '' Or StringInStr(_WinAPI_GetProcessCommandLine($iPID), $sCmdLine))
If (@AutoItPID <> $iPID) And Not $bVisible And $bPath And $bCmdLine Then
$hWnd = $aWinList[$i][1]
ExitLoop
EndIf
Next
EndIf
If Not $hWnd Then
$hWnd = WinGetHandle($sTitle)
EndIf
Return SetError((IsHWnd($hWnd) ? 0 : 1), 0, $hWnd)
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_ReadProcessMemory
; Description ...: Reads process memory by pointer and returns structure.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_ReadProcessMemory($iPID, $pPointer, $sStructTag)
Local $hProcess, $stStruct, $iSize, $pStruct, $iRead
$hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID)
If @error Then Return SetError(@error, 1, 0)
$stStruct = DllStructCreate($sStructTag)
$iSize = DllStructGetSize($stStruct)
$pStruct = DllStructGetPtr($stStruct)
_WinAPI_ReadProcessMemory($hProcess, $pPointer, $pStruct, $iSize, $iRead)
_WinAPI_CloseHandle($hProcess)
Return SetError(@error, $iRead, $stStruct)
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_WriteProcessMemoryPtr
; Description ...: Writes to process memory by pointer.
; Author ........: Danyfirex (mod. by G.Sandler)
; ===============================================================================================================================
Func __AppInteract_WriteProcessMemoryPtr($iPID, $pPointer, $ptPtr)
Local $hProcess, $stData, $iSize, $pData, $bWrite, $iWriten
$hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, False, $iPID)
If @error Then Return SetError(@error, 1, 0)
$stData = DllStructCreate('ptr pData')
$iSize = DllStructGetSize($stData)
$pData = DllStructGetPtr($stData)
DllStructSetData($stData, 'pData', $ptPtr)
$bWrite = _WinAPI_WriteProcessMemory($hProcess, $pPointer, $pData, $iSize, $iWriten)
_WinAPI_CloseHandle($hProcess)
Return SetError(@error, $iWriten, $bWrite)
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_WM_COPYDATA
; Description ...: Interaction handler.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_WM_COPYDATA($hWnd, $iMsg, $wParam, $lParam)
If $hWnd <> $APPINTRCT_HWND Then
Return 'GUI_RUNDEFMSG'
EndIf
Local $tCopyData, $tData, $sStr, $vRet, $iLen
Local Static $stStr
$tCopyData = DllStructCreate($tagCOPYDATASTRUCT, $lParam)
$tData = DllStructCreate('Ptr pReturn;long iPID;wchar sData[' & (DllStructGetData($tCopyData, 'cbData') - (@AutoItX64 ? 12 : 8)) & ']', DllStructGetData($tCopyData, 'lpData'))
$sStr = __AppInteract_Variant_UnPack(DllStructGetData($tData, 'sData'))
$vRet = Call($APPINTRCT_RECEIVER, $sStr)
$vRet = __AppInteract_Variant_Pack($vRet)
If @error Then
Return 'GUI_RUNDEFMSG'
EndIf
$iLen = (StringLen($vRet) + 1)
$stStr = DllStructCreate('long iSize;wchar sStr[' & $iLen & ']')
DllStructSetData($stStr, 'iSize', $iLen)
DllStructSetData($stStr, 'sStr', $vRet)
Return __AppInteract_WriteProcessMemoryPtr(DllStructGetData($tData, 'iPID'), DllStructGetData($tData, 'pReturn'), DllStructGetPtr($stStr))
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_Pack
; Description ...: Pack variable to string.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_Pack($vData)
If Not __AppInteract_Variant_IsSupportedType($vData) Then
Return SetError(1, 0, $vData)
EndIf
Local $sVarType = VarGetType($vData)
If $sVarType <> 'Array' Then
If $sVarType = 'Ptr' And HWnd($vData) Then
Return '[HWnd]' & String($vData)
EndIf
If $sVarType = 'Function' Or $sVarType = 'UserFunction' Then
$vData = FuncName($vData)
EndIf
Return '[' & $sVarType & ']' & String($vData)
EndIf
Local $sRet = ''
Local $iDim = UBound($vData, $UBOUND_DIMENSIONS)
Switch $iDim
Case 1
For $iRow = 0 To UBound($vData, $UBOUND_ROWS) - 1
$sRet &= ($sRet ? $APPINTRCT_VRNT_ROW_SEP : '') & __AppInteract_Variant_Pack($vData[$iRow])
Next
Case 2
For $iRow = 0 To UBound($vData, $UBOUND_ROWS) - 1
$sRet &= ($iRow ? $APPINTRCT_VRNT_COL_SEP : '')
For $iCol = 0 To UBound($vData, $UBOUND_COLUMNS) - 1
$sRet &= ($iCol ? $APPINTRCT_VRNT_ROW_SEP : '') & __AppInteract_Variant_Pack($vData[$iRow][$iCol])
Next
Next
EndSwitch
Return '[Array,' & $iDim & ']' & $sRet
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_UnPack
; Description ...: UnPack string to variable (preserving data types).
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_UnPack($sData)
If Not __AppInteract_Variant_IsSupportedType($sData) Then
Return SetError(1, 0, $sData)
EndIf
Local $aData = StringRegExp($sData, '(?s)^\[((?:' & $APPINTRCT_VAR_TYPES & ')(?:,\d)?)\](.*)$', 1)
If UBound($aData) < 2 Then
Return $sData
EndIf
Local $vRet = $aData[1]
Local $iDim = Int(StringRegExpReplace($aData[0], '^.*,(\d)$', '\1'))
If $iDim Then
$aData[0] = StringTrimRight($aData[0], 2) ;Remove array dimension
EndIf
Switch $aData[0]
Case 'Int32', 'Int64', 'Double'
$vRet = Number($aData[1])
Case 'Bool'
$vRet = ($aData[1] = 'True')
Case 'String', 'Binary', 'Ptr', 'HWnd'
Local $hFunc = Execute($aData[0])
$vRet = $hFunc($aData[1])
Case 'Keyword'
$vRet = ($aData[1] = 'Default' ? Default : Null)
Case 'Function', 'UserFunction'
$vRet = Execute($aData[1])
Case 'Array'
Switch $iDim
Case 1
$vRet = StringSplit($aData[1], $APPINTRCT_VRNT_ROW_SEP, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
For $i = 0 To UBound($vRet, $UBOUND_ROWS) - 1
$vRet[$i] = __AppInteract_Variant_UnPack($vRet[$i])
Next
Case 2
Local $aRows = StringSplit($aData[1], $APPINTRCT_VRNT_COL_SEP, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
Local $iRows = UBound($aRows, $UBOUND_ROWS)
Local $iCols
Dim $vRet[$iRows][1]
For $iRow = 0 To $iRows - 1
$aCols = StringSplit($aRows[$iRow], $APPINTRCT_VRNT_ROW_SEP, BitOR($STR_ENTIRESPLIT, $STR_NOCOUNT))
$iCols = UBound($aCols, $UBOUND_ROWS)
ReDim $vRet[$iRows][$iCols]
For $iCol = 0 To $iCols - 1
$vRet[$iRow][$iCol] = __AppInteract_Variant_UnPack($aCols[$iCol])
Next
Next
EndSwitch
EndSwitch
Return $vRet
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_IsSupportedType
; Description ...: Checks if a given data is supported data type.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_IsSupportedType($vData)
Switch VarGetType($vData)
Case 'Array'
If UBound($vData, $UBOUND_DIMENSIONS) > 2 Then
Return False
EndIf
Case 'Object', 'DllStruct'
Return False
EndSwitch
Return True
EndFunc
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __AppInteract_Variant_GetTypes
; Description ...: Gets all(?) AutoIt variable types.
; Author ........: G.Sandler
; ===============================================================================================================================
Func __AppInteract_Variant_GetTypes($bArr = False)
Local $aVars[] = _
[ _
StringSplit('', ''), Binary('0'), True, Ptr(-1), WinGetHandle(''), 1, DllStructSetData(DllStructCreate('int64'), 1, 1), 2.0, _
ObjCreate('Scripting.Dictionary'), 'a', DllStructCreate('int'), Default, Int, __AppInteract_Variant_GetTypes _
]
Local $sType, $sTypes = ''
For $i = 0 To UBound($aVars) - 1
$sType = VarGetType($aVars[$i])
$sTypes &= ($sTypes ? '|' : '') & (($sType = 'Ptr' And HWnd($aVars[$i])) ? 'HWnd' : $sType)
$aVars[$i] = 0
Next
If $bArr Then
$sTypes = StringSplit($sTypes, '|')
EndIf
Return $sTypes
EndFunc
GeSHi © Extension Codebox Plus
► Afficher le texte
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <Array.au3>
#include <AppInteract.au3>
Global $iApp = 1
Global $sApp_Name = 'My App' & $iApp
Global $sSend_App_Name = 'My App' & Mod($iApp, 2) + 1
Global $sSend_Script_Name = 'Script' & Mod($iApp, 2) + 1 & '.' & (@Compiled ? 'exe' : 'au3')
Global $iGUI_Width = 600
Global $iGUI_Left = 100 + ($iGUI_Width * ($iApp - 1)) + (10 * ($iApp - 1))
_AppInteract_SetReceiver($sApp_Name, '_Receiver')
$hGUI = GUICreate(@ScriptName & ' - AppInteract Example', $iGUI_Width, 400, $iGUI_Left, 20)
GUICtrlCreateLabel('Please run ' & $sSend_Script_Name & ' and enter some data to send:', 10, 5, -1, 15)
$iEdit = GUICtrlCreateEdit(StringFormat('Send\r\nThis\r\nData\r\nTo\r\n%s', $sSend_Script_Name), 10, 20, 580, 150)
GUICtrlCreateLabel('Received:', 10, 175, -1, 15)
$iReceiver_LV = GUICtrlCreateListView('Type|Data', 10, 190, 580, 170)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 0, 285)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 1, 285)
GUICtrlCreateLabel('Send to ' & $sSend_Script_Name & ' as:', 20, 373)
$iSendStr_Bttn = GUICtrlCreateButton('String', 150, 370, 70, 20)
$iSendArr_Bttn = GUICtrlCreateButton('Array', 230, 370, 70, 20)
$iSendBin_Bttn = GUICtrlCreateButton('Binary', 310, 370, 70, 20)
GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop($hGUI, '', 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $iSendStr_Bttn, $iSendArr_Bttn, $iSendBin_Bttn
$vData = GUICtrlRead($iEdit)
Switch $nMsg
Case $iSendArr_Bttn
$vData = StringSplit(StringStripCR($vData), @LF)
Case $iSendBin_Bttn
$vData = StringToBinary($vData)
EndSwitch
_AppInteract_Send($sSend_App_Name, $vData, @AutoItExe)
If @error Then
MsgBox(48, @ScriptName, 'Unable to send, probably ' & $sSend_Script_Name & ' is not executed!', 0, $hGUI)
EndIf
EndSwitch
WEnd
Func _Receiver($vData)
Local $sData = $vData
Local $sType = VarGetType($vData)
Switch $sType
Case 'Array'
$sData = _ArrayToString($vData, '~', -1, -1, Chr(10))
Case 'Binary'
$sData = BinaryToString($vData)
EndSwitch
GUICtrlCreateListViewItem($sType & '|' & $sData, $iReceiver_LV)
EndFunc
#include <ListViewConstants.au3>
#include <Array.au3>
#include <AppInteract.au3>
Global $iApp = 1
Global $sApp_Name = 'My App' & $iApp
Global $sSend_App_Name = 'My App' & Mod($iApp, 2) + 1
Global $sSend_Script_Name = 'Script' & Mod($iApp, 2) + 1 & '.' & (@Compiled ? 'exe' : 'au3')
Global $iGUI_Width = 600
Global $iGUI_Left = 100 + ($iGUI_Width * ($iApp - 1)) + (10 * ($iApp - 1))
_AppInteract_SetReceiver($sApp_Name, '_Receiver')
$hGUI = GUICreate(@ScriptName & ' - AppInteract Example', $iGUI_Width, 400, $iGUI_Left, 20)
GUICtrlCreateLabel('Please run ' & $sSend_Script_Name & ' and enter some data to send:', 10, 5, -1, 15)
$iEdit = GUICtrlCreateEdit(StringFormat('Send\r\nThis\r\nData\r\nTo\r\n%s', $sSend_Script_Name), 10, 20, 580, 150)
GUICtrlCreateLabel('Received:', 10, 175, -1, 15)
$iReceiver_LV = GUICtrlCreateListView('Type|Data', 10, 190, 580, 170)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 0, 285)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 1, 285)
GUICtrlCreateLabel('Send to ' & $sSend_Script_Name & ' as:', 20, 373)
$iSendStr_Bttn = GUICtrlCreateButton('String', 150, 370, 70, 20)
$iSendArr_Bttn = GUICtrlCreateButton('Array', 230, 370, 70, 20)
$iSendBin_Bttn = GUICtrlCreateButton('Binary', 310, 370, 70, 20)
GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop($hGUI, '', 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $iSendStr_Bttn, $iSendArr_Bttn, $iSendBin_Bttn
$vData = GUICtrlRead($iEdit)
Switch $nMsg
Case $iSendArr_Bttn
$vData = StringSplit(StringStripCR($vData), @LF)
Case $iSendBin_Bttn
$vData = StringToBinary($vData)
EndSwitch
_AppInteract_Send($sSend_App_Name, $vData, @AutoItExe)
If @error Then
MsgBox(48, @ScriptName, 'Unable to send, probably ' & $sSend_Script_Name & ' is not executed!', 0, $hGUI)
EndIf
EndSwitch
WEnd
Func _Receiver($vData)
Local $sData = $vData
Local $sType = VarGetType($vData)
Switch $sType
Case 'Array'
$sData = _ArrayToString($vData, '~', -1, -1, Chr(10))
Case 'Binary'
$sData = BinaryToString($vData)
EndSwitch
GUICtrlCreateListViewItem($sType & '|' & $sData, $iReceiver_LV)
EndFunc
GeSHi © Extension Codebox Plus
► Afficher le texte
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <Array.au3>
#include <AppInteract.au3>
Global $iApp = 2
Global $sApp_Name = 'My App' & $iApp
Global $sSend_App_Name = 'My App' & Mod($iApp, 2) + 1
Global $sSend_Script_Name = 'Script' & Mod($iApp, 2) + 1 & '.' & (@Compiled ? 'exe' : 'au3')
Global $iGUI_Width = 600
Global $iGUI_Left = 100 + ($iGUI_Width * ($iApp - 1)) + (10 * ($iApp - 1))
_AppInteract_SetReceiver($sApp_Name, '_Receiver')
$hGUI = GUICreate(@ScriptName & ' - AppInteract Example', $iGUI_Width, 400, $iGUI_Left, 20)
GUICtrlCreateLabel('Please run ' & $sSend_Script_Name & ' and enter some data to send:', 10, 5, -1, 15)
$iEdit = GUICtrlCreateEdit(StringFormat('Send\r\nThis\r\nData\r\nTo\r\n%s', $sSend_Script_Name), 10, 20, 580, 150)
GUICtrlCreateLabel('Received:', 10, 175, -1, 15)
$iReceiver_LV = GUICtrlCreateListView('Type|Data', 10, 190, 580, 170)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 0, 285)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 1, 285)
GUICtrlCreateLabel('Send to ' & $sSend_Script_Name & ' as:', 20, 373)
$iSendStr_Bttn = GUICtrlCreateButton('String', 150, 370, 70, 20)
$iSendArr_Bttn = GUICtrlCreateButton('Array', 230, 370, 70, 20)
$iSendBin_Bttn = GUICtrlCreateButton('Binary', 310, 370, 70, 20)
GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop($hGUI, '', 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $iSendStr_Bttn, $iSendArr_Bttn, $iSendBin_Bttn
$vData = GUICtrlRead($iEdit)
Switch $nMsg
Case $iSendArr_Bttn
$vData = StringSplit(StringStripCR($vData), @LF)
Case $iSendBin_Bttn
$vData = StringToBinary($vData)
EndSwitch
_AppInteract_Send($sSend_App_Name, $vData, @AutoItExe)
If @error Then
MsgBox(48, @ScriptName, 'Unable to send, probably ' & $sSend_Script_Name & ' is not executed!', 0, $hGUI)
EndIf
EndSwitch
WEnd
Func _Receiver($vData)
Local $sData = $vData
Local $sType = VarGetType($vData)
Switch $sType
Case 'Array'
$sData = _ArrayToString($vData, '~', -1, -1, Chr(10))
Case 'Binary'
$sData = BinaryToString($vData)
EndSwitch
GUICtrlCreateListViewItem($sType & '|' & $sData, $iReceiver_LV)
EndFunc
#include <ListViewConstants.au3>
#include <Array.au3>
#include <AppInteract.au3>
Global $iApp = 2
Global $sApp_Name = 'My App' & $iApp
Global $sSend_App_Name = 'My App' & Mod($iApp, 2) + 1
Global $sSend_Script_Name = 'Script' & Mod($iApp, 2) + 1 & '.' & (@Compiled ? 'exe' : 'au3')
Global $iGUI_Width = 600
Global $iGUI_Left = 100 + ($iGUI_Width * ($iApp - 1)) + (10 * ($iApp - 1))
_AppInteract_SetReceiver($sApp_Name, '_Receiver')
$hGUI = GUICreate(@ScriptName & ' - AppInteract Example', $iGUI_Width, 400, $iGUI_Left, 20)
GUICtrlCreateLabel('Please run ' & $sSend_Script_Name & ' and enter some data to send:', 10, 5, -1, 15)
$iEdit = GUICtrlCreateEdit(StringFormat('Send\r\nThis\r\nData\r\nTo\r\n%s', $sSend_Script_Name), 10, 20, 580, 150)
GUICtrlCreateLabel('Received:', 10, 175, -1, 15)
$iReceiver_LV = GUICtrlCreateListView('Type|Data', 10, 190, 580, 170)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 0, 285)
GUICtrlSendMsg($iReceiver_LV, $LVM_SETCOLUMNWIDTH, 1, 285)
GUICtrlCreateLabel('Send to ' & $sSend_Script_Name & ' as:', 20, 373)
$iSendStr_Bttn = GUICtrlCreateButton('String', 150, 370, 70, 20)
$iSendArr_Bttn = GUICtrlCreateButton('Array', 230, 370, 70, 20)
$iSendBin_Bttn = GUICtrlCreateButton('Binary', 310, 370, 70, 20)
GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop($hGUI, '', 1)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $iSendStr_Bttn, $iSendArr_Bttn, $iSendBin_Bttn
$vData = GUICtrlRead($iEdit)
Switch $nMsg
Case $iSendArr_Bttn
$vData = StringSplit(StringStripCR($vData), @LF)
Case $iSendBin_Bttn
$vData = StringToBinary($vData)
EndSwitch
_AppInteract_Send($sSend_App_Name, $vData, @AutoItExe)
If @error Then
MsgBox(48, @ScriptName, 'Unable to send, probably ' & $sSend_Script_Name & ' is not executed!', 0, $hGUI)
EndIf
EndSwitch
WEnd
Func _Receiver($vData)
Local $sData = $vData
Local $sType = VarGetType($vData)
Switch $sType
Case 'Array'
$sData = _ArrayToString($vData, '~', -1, -1, Chr(10))
Case 'Binary'
$sData = BinaryToString($vData)
EndSwitch
GUICtrlCreateListViewItem($sType & '|' & $sData, $iReceiver_LV)
EndFunc
GeSHi © Extension Codebox Plus
► Afficher le texte
#include-once
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <AVIConstants.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiComboBox.au3>
#include <ScrollBarsConstants.au3>
#include <Array.au3>
#Include <WinAPIEx.au3>
#include <GuiEdit.au3>
#include <WinAPIFiles.au3>
#include <GuiSlider.au3>
#include <ColorConstants.au3>
#include <WinAPITheme.au3>
#include <Date.au3>
#include <String.au3>
#include <Misc.au3>
#RequireAdmin
#NoTrayIcon
Global Const $Title = "Essai"
#Region ### START Koda GUI section ### Form=
$MainGui = GUICreate($Title, 494, 852, -1, -1, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Group1 = GUICtrlCreateGroup("1", 8, 10, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group1), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo1 = GUICtrlCreateCombo("", 18, 30, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit1 = GUICtrlCreateEdit("", 18, 87, 209, 113)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Start 1", 18, 57, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("2", 250, 10, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group2), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo2 = GUICtrlCreateCombo("", 260, 30, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit2 = GUICtrlCreateEdit("", 260, 87, 209, 113)
GUICtrlSetData(-1, "")
$Button2 = GUICtrlCreateButton("Start 2", 260, 57, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("3", 9, 220, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group3), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo3 = GUICtrlCreateCombo("", 19, 240, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit3 = GUICtrlCreateEdit("", 19, 297, 209, 113)
GUICtrlSetData(-1, "")
$Button3 = GUICtrlCreateButton("Start 3", 19, 267, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("4", 250, 220, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group4), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo4 = GUICtrlCreateCombo("", 260, 240, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit4 = GUICtrlCreateEdit("", 260, 297, 209, 113)
GUICtrlSetData(-1, "")
$Button4 = GUICtrlCreateButton("Start 4", 260, 267, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("5", 10, 425, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group5), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo5 = GUICtrlCreateCombo("", 20, 445, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit5 = GUICtrlCreateEdit("", 20, 502, 209, 113)
GUICtrlSetData(-1, "")
$Button5 = GUICtrlCreateButton("Start 5", 20, 472, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group6 = GUICtrlCreateGroup("6", 250, 425, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group6), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo6 = GUICtrlCreateCombo("", 260, 445, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit6 = GUICtrlCreateEdit("", 260, 502, 209, 113)
GUICtrlSetData(-1, "")
$Button6 = GUICtrlCreateButton("Start 6", 260, 472, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group7 = GUICtrlCreateGroup("7", 10, 640, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group7), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo7 = GUICtrlCreateCombo("", 20, 660, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit7 = GUICtrlCreateEdit("", 20, 717, 209, 113)
GUICtrlSetData(-1, "")
$Button7 = GUICtrlCreateButton("Start 7", 20, 687, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group8 = GUICtrlCreateGroup("8", 250, 640, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group8), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo8 = GUICtrlCreateCombo("", 260, 660, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit8 = GUICtrlCreateEdit("", 260, 717, 209, 113)
GUICtrlSetData(-1, "")
$Button8 = GUICtrlCreateButton("Start 8", 260, 687, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <AVIConstants.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiComboBox.au3>
#include <ScrollBarsConstants.au3>
#include <Array.au3>
#Include <WinAPIEx.au3>
#include <GuiEdit.au3>
#include <WinAPIFiles.au3>
#include <GuiSlider.au3>
#include <ColorConstants.au3>
#include <WinAPITheme.au3>
#include <Date.au3>
#include <String.au3>
#include <Misc.au3>
#RequireAdmin
#NoTrayIcon
Global Const $Title = "Essai"
#Region ### START Koda GUI section ### Form=
$MainGui = GUICreate($Title, 494, 852, -1, -1, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Group1 = GUICtrlCreateGroup("1", 8, 10, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group1), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo1 = GUICtrlCreateCombo("", 18, 30, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit1 = GUICtrlCreateEdit("", 18, 87, 209, 113)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Start 1", 18, 57, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("2", 250, 10, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group2), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo2 = GUICtrlCreateCombo("", 260, 30, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit2 = GUICtrlCreateEdit("", 260, 87, 209, 113)
GUICtrlSetData(-1, "")
$Button2 = GUICtrlCreateButton("Start 2", 260, 57, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("3", 9, 220, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group3), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo3 = GUICtrlCreateCombo("", 19, 240, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit3 = GUICtrlCreateEdit("", 19, 297, 209, 113)
GUICtrlSetData(-1, "")
$Button3 = GUICtrlCreateButton("Start 3", 19, 267, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("4", 250, 220, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group4), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo4 = GUICtrlCreateCombo("", 260, 240, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit4 = GUICtrlCreateEdit("", 260, 297, 209, 113)
GUICtrlSetData(-1, "")
$Button4 = GUICtrlCreateButton("Start 4", 260, 267, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group5 = GUICtrlCreateGroup("5", 10, 425, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group5), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo5 = GUICtrlCreateCombo("", 20, 445, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit5 = GUICtrlCreateEdit("", 20, 502, 209, 113)
GUICtrlSetData(-1, "")
$Button5 = GUICtrlCreateButton("Start 5", 20, 472, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group6 = GUICtrlCreateGroup("6", 250, 425, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group6), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo6 = GUICtrlCreateCombo("", 260, 445, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit6 = GUICtrlCreateEdit("", 260, 502, 209, 113)
GUICtrlSetData(-1, "")
$Button6 = GUICtrlCreateButton("Start 6", 260, 472, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group7 = GUICtrlCreateGroup("7", 10, 640, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group7), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo7 = GUICtrlCreateCombo("", 20, 660, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit7 = GUICtrlCreateEdit("", 20, 717, 209, 113)
GUICtrlSetData(-1, "")
$Button7 = GUICtrlCreateButton("Start 7", 20, 687, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group8 = GUICtrlCreateGroup("8", 250, 640, 233, 201)
_WinAPI_SetWindowTheme(GUICtrlGetHandle($Group8), "", "")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x004080)
$Combo8 = GUICtrlCreateCombo("", 260, 660, 153, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Edit8 = GUICtrlCreateEdit("", 260, 717, 209, 113)
GUICtrlSetData(-1, "")
$Button8 = GUICtrlCreateButton("Start 8", 260, 687, 75, 25)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
GeSHi © Extension Codebox Plus
Les différents Edit me servirons à indiquer le statuts du programme en cours:
"En cours" - "A l'arrêt" - "Exécute l'étape 1" - "Exécute l'étape 2" ect...
Et là est mon premier soucis, dois-je utiliser un Edit sachant que les programmes devront principalement lire les derniers messages et j'ai peur que cela ne risque de créer des confusion, a moins qu'il y a un moyen d'avoir une lecture uniquement du dernier message ?
Ou alors je vais devoir utiliser autre chose ?
Et là deuxième soucis que je rencontre,
Comment est-ce que je pourrais indiquer au programme 2 ou 3 de lire le dernier message de l'edit du programme 1 ?
Se serait principalement attendre le "Envoyer" du programme 1 pour exécuter son action.
C'est uniquement pour "la gloire", je me répète mais je sais qu'il y a plus simple, c'est justement le fait de pouvoir faire une synchronisation des programmes via l'interface qui m'intéresse

Dans l'attente de votre aide, Merci d'avance
