anixon Posted December 12, 2010 Posted December 12, 2010 At the moment I have two scripts running similtaneously which on occasions need to communicate with each other by pass from one to the other a simple processing switch/flag 1 to process 0 not to process. At the moment I am writing the switch/ flag to an ini file which is read by the processing script. This method on occasions may cause a write read timing issue base on where the scripts processing cycle is at. In other words it misses a process and has to wait for the next cycle. Is their any way that scripts can read a global variable like Global $Process = 1 that is a unique variable in another script. Assistance is always appreciated. Ant..
Moderators Melba23 Posted December 12, 2010 Moderators Posted December 12, 2010 anixon,If you search for "+inter +process +communication" you will find a fair number of such things on the forum. My personal favourites are trancexx's MailSlot UDF and the one from Yashied on which this is based:expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Based on code from Yashied #include <GUIConstantsEx.au3> #Include <WinApi.au3> Opt("WinTitleMatchMode", 3) Global Const $WM_MYMSG = _WinAPI_RegisterWindowMessage('WM_MYMSG') Global Const $HWND_BROADCAST = 0xFFFF Global $sThis_Win_Title, $sThat_Win_Title Global $iY, $hInput, $hButton, $hLabel Global $iValue_To_Send Global $iValue_Rcvd = Default ; Set GUI title If WinExists("First Instance") Then If WinExists("Second Instance") Then Exit $sThis_Win_Title = "Second Instance" $sThat_Win_Title = "First Instance" $iY = 300 Else $sThis_Win_Title = "First Instance" $sThat_Win_Title = "Second Instance" $iY = 100 EndIf ; Create GUI $hGUI = GUICreate($sThis_Win_Title, 400, 150, 100, $iY) $hInput = GUICtrlCreateInput("", 20, 20, 360, 20) $hButton = GUICtrlCreateButton("Send", 160, 60, 80, 30) $hLabel = GUICtrlCreateLabel("", 20, 100, 360, 20) GUIRegisterMsg($WM_MYMSG, 'WM_MYMSG') GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Send exit message to all windows _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, -999999, $hGUI) Case $hButton ; Send message to other window $sValue_To_Send = Number(GUICtrlRead($hInput)) If IsNumber($sValue_To_Send) Then _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, $sValue_To_Send, $hGUI) GUICtrlSetData($hInput, "") EndSwitch ; Check messages received If $iValue_Rcvd = -999999 Then Exit If $iValue_Rcvd <> Default Then GUICtrlSetData($hLabel, Number($iValue_Rcvd)) $iValue_Rcvd = Default EndIf WEnd Func WM_MYMSG($hWnd, $iMsg, $wParam, $lParam) ; Only react if sent from another GUI If $lParam <> $hGUI Then $iValue_Rcvd = $wParam ; Unless it is the exit signal If $wParam = -999999 Then $iValue_Rcvd = $wParam EndFunc ;==>WM_MYMSGJust compile and run the exe twice. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
anixon Posted December 12, 2010 Author Posted December 12, 2010 anixon, If you search for "+inter +process +communication" you will find a fair number of such things on the forum. My personal favourites are trancexx's MailSlot UDF and the one from Yashied on which this is based: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Based on code from Yashied #include <GUIConstantsEx.au3> #Include <WinApi.au3> Opt("WinTitleMatchMode", 3) Global Const $WM_MYMSG = _WinAPI_RegisterWindowMessage('WM_MYMSG') Global Const $HWND_BROADCAST = 0xFFFF Global $sThis_Win_Title, $sThat_Win_Title Global $iY, $hInput, $hButton, $hLabel Global $iValue_To_Send Global $iValue_Rcvd = Default ; Set GUI title If WinExists("First Instance") Then If WinExists("Second Instance") Then Exit $sThis_Win_Title = "Second Instance" $sThat_Win_Title = "First Instance" $iY = 300 Else $sThis_Win_Title = "First Instance" $sThat_Win_Title = "Second Instance" $iY = 100 EndIf ; Create GUI $hGUI = GUICreate($sThis_Win_Title, 400, 150, 100, $iY) $hInput = GUICtrlCreateInput("", 20, 20, 360, 20) $hButton = GUICtrlCreateButton("Send", 160, 60, 80, 30) $hLabel = GUICtrlCreateLabel("", 20, 100, 360, 20) GUIRegisterMsg($WM_MYMSG, 'WM_MYMSG') GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ; Send exit message to all windows _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, -999999, $hGUI) Case $hButton ; Send message to other window $sValue_To_Send = Number(GUICtrlRead($hInput)) If IsNumber($sValue_To_Send) Then _WinAPI_PostMessage($HWND_BROADCAST, $WM_MYMSG, $sValue_To_Send, $hGUI) GUICtrlSetData($hInput, "") EndSwitch ; Check messages received If $iValue_Rcvd = -999999 Then Exit If $iValue_Rcvd <> Default Then GUICtrlSetData($hLabel, Number($iValue_Rcvd)) $iValue_Rcvd = Default EndIf WEnd Func WM_MYMSG($hWnd, $iMsg, $wParam, $lParam) ; Only react if sent from another GUI If $lParam <> $hGUI Then $iValue_Rcvd = $wParam ; Unless it is the exit signal If $wParam = -999999 Then $iValue_Rcvd = $wParam EndFunc ;==>WM_MYMSG Just compile and run the exe twice. M23 Thanks M23 that works perfectly I will however need to do some mods to remove the user input and 'send' functionality and given that the messaging is one way only there is probably no need for two windows. Great help like this is always appreciated thanks again. Ant..
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now