JAFN Posted May 20, 2011 Share Posted May 20, 2011 I have a script that may have several instances running. I would like to have them dock top to bottom and also for only the first instance to record its location. Is there a way to access the order of previous instances and to get their locations? [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
martin Posted May 21, 2011 Share Posted May 21, 2011 (edited) I have a script that may have several instances running. I would like to have them dock top to bottom and also for only the first instance to record its location. Is there a way to access the order of previous instances and to get their locations? You could do something like this #include <misc.au3> Global $instance = True, $inst = 0 While $instance = True $inst += 1 _Singleton("MySpecialAppxyz" & $inst, 1) $instance = @error = 183 WEnd $ht = 200 $wd = 200 $wintop = 0 If $inst > 1 Then $pos = WinGetPos("SameTitle");gets pos of first inst ;$pos = wingetpos(""DifferentTitle" & $inst - 1) $wintop = $pos[1] + $pos[3] EndIf $Gui = GUICreate("SameTitle", $ht, $wd, 0, $wintop) ;$Gui = GUICreate("DifferentTitle" & $inst,$ht,$wd,0,$ht*($inst - 1)) GUISetState() While GUIGetMsg() <> -3 WEnd But if any of the windows is closed it might mess things up, so you could check every so often. I think I would register a unique message and set things so that if an instance closes it closes all instances after it. Edited May 21, 2011 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JAFN Posted May 21, 2011 Author Share Posted May 21, 2011 You could do something like this #include <misc.au3> Global $instance = True, $inst = 0 While $instance = True $inst += 1 _Singleton("MySpecialAppxyz" & $inst, 1) $instance = @error = 183 WEnd $ht = 200 $wd = 200 $wintop = 0 If $inst > 1 Then $pos = WinGetPos("SameTitle");gets pos of first inst ;$pos = wingetpos(""DifferentTitle" & $inst - 1) $wintop = $pos[1] + $pos[3] EndIf $Gui = GUICreate("SameTitle", $ht, $wd, 0, $wintop) ;$Gui = GUICreate("DifferentTitle" & $inst,$ht,$wd,0,$ht*($inst - 1)) Wow. I was expecting that if it could be done it would be long and arcane. I was able to adapt it to my program with minimal trouble and it works perfectly. However I do not understand this important section While $instance = True $inst += 1 _Singleton("MySpecialAppxyz" & $inst, 1) $instance = @error = 183 WEnd Is '"MySpecialAppxyz"' simply a title unlikely to be found? And how even if so, I don't get what this section does. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
martin Posted May 21, 2011 Share Posted May 21, 2011 Yes, singleton registers a mutex which is (my undertsnading) a mutually exclusive string. It ties a mutex handle to the string. So if you register a string which hopefully only you would have in your script then you can see if windows has a record of this string. The process which first creates the mutex destroys it when it closes. If windows has a record of the string then there must be another of your scripts running. In this case we don't just want to know if an instance is running but we want to know how many. So I added a number to the end of the string. (So make sure the original string doesn't end wich a digit.) We try _Singleton to see if the string has been registered and if it has, because _Singleton with the flag set to 1 gives an error of 183, then we try the next number. As soon as _Singleton doesn't set error to 183 we know that we are that number. The error = 183 means that the mutex already exists. I hope that makes sense. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JAFN Posted May 21, 2011 Author Share Posted May 21, 2011 Yes, singleton registers a mutex which is (my undertsnading) a mutually exclusive string. It ties a mutex handle to the string. So if you register a string which hopefully only you would have in your script then you can see if windows has a record of this string. The process which first creates the mutex destroys it when it closes. If windows has a record of the string then there must be another of your scripts running.In this case we don't just want to know if an instance is running but we want to know how many. So I added a number to the end of the string. (So make sure the original string doesn't end wich a digit.) We try _Singleton to see if the string has been registered and if it has, because _Singleton with the flag set to 1 gives an error of 183, then we try the next number. As soon as _Singleton doesn't set error to 183 we know that we are that number. The error = 183 means that the mutex already exists.I hope that makes sense.If I understand you right all that part of the code does is determine by '$inst > 1' that there are at least one other instance running.Correct? [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
martin Posted May 21, 2011 Share Posted May 21, 2011 If I understand you right all that part of the code does is determine by '$inst > 1' that there are at least one other instance running.Correct?Not to see if another is running but to count how many. Each new instance registers a new string.When a script runs it tries to register a string MySpecialAppxyz1 If that is successful then this is the first script, and now we have MySpecialAppxyz1 registered.Now another script is started. It also tries to register MySpecialAppxyz1 but that produces an error, so there must be at least one instance running. Then it tries to register MySpecialAppxyz2 and that is successful and now we also have MySpecialAppxyz2 registered. Now another script is started. It also tries to register MySpecialAppxyz1 but that produces an error, so there must be at least one instance running. Then it tries to register MySpecialAppxyz2 and that is successful and now we also have MySpecialAppxyz1 but that produces an error, so there must be at least two instances running which have already registered MySpecialAppxyz1 and MySpecialAppxyz2, so it tries MySpecialAppxyz3... and so on. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JAFN Posted May 21, 2011 Author Share Posted May 21, 2011 Not to see if another is running but to count how many. Each new instance registers a new string.When a script runs it tries to register a string MySpecialAppxyz1 If that is successful then this is the first script, and now we have MySpecialAppxyz1 registered.Now another script is started. It also tries to register MySpecialAppxyz1 but that produces an error, so there must be at least one instance running. Then it tries to register MySpecialAppxyz2 and that is successful and now we also have MySpecialAppxyz2 registered. Now another script is started. It also tries to register MySpecialAppxyz1 but that produces an error, so there must be at least one instance running. Then it tries to register MySpecialAppxyz2 and that is successful and now we also have MySpecialAppxyz1 but that produces an error, so there must be at least two instances running which have already registered MySpecialAppxyz1 and MySpecialAppxyz2, so it tries MySpecialAppxyz3... and so on.How does it get registered? Does _Singleton do more than I thought it did? [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
martin Posted May 21, 2011 Share Posted May 21, 2011 How does it get registered? Does _Singleton do more than I thought it did?Evidently.Have a look at the _Singleton function in misc.au3. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JAFN Posted May 21, 2011 Author Share Posted May 21, 2011 Evidently.Have a look at the _Singleton function in misc.au3.Oh that hurt my head.But based on what I have I am going to try to write an aligning routine to run when each new instance opens.Be back much later, most likely.Thank you. [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Yashied Posted May 21, 2011 Share Posted May 21, 2011 Another way.#Include <WinAPIEx.au3> $hSemaphore = _WinAPI_CreateSemaphore('MySemaphore', 0, 65535) $Count = _WinAPI_ReleaseSemaphore($hSemaphore) + 1 _MyGUI('#' & $Count) _WinAPI_CloseHandle($hSemaphore) Func _MyGUI($sTitle) Local $Msg GUICreate($sTitle) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 ExitLoop EndSwitch WEnd EndFunc ;==>_MyGUI My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
martin Posted May 21, 2011 Share Posted May 21, 2011 Another way. #Include <WinAPIEx.au3> $hSemaphore = _WinAPI_CreateSemaphore('MySemaphore', 0, 65535) $Count = _WinAPI_ReleaseSemaphore($hSemaphore) + 1 _MyGUI('#' & $Count) _WinAPI_CloseHandle($hSemaphore) Func _MyGUI($sTitle) Local $Msg GUICreate($sTitle) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case -3 ExitLoop EndSwitch WEnd EndFunc ;==>_MyGUI I like that method, but I don't understand what happens when a process closes. Can the semaphore count be decremented? Th edisadvantage I suppose is that you can't tell if the third instance is running but the second is not.. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
JAFN Posted May 21, 2011 Author Share Posted May 21, 2011 Okay. I have 3 windows all starting with (-). Why does the comment line never get reached? OrderWindow() Func OrderWindow() $Marker = "(-)" $First = True $List = ProcessList() $Items = $List[0][0] ; MsgBox(0,"",$Items) If $Items < 1 Then Return For $x = $Items To 1 Step -1 If $Marker <> $List[$x][0] Then ContinueLoop ; code never gets here Next EndFunc [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
Yashied Posted May 21, 2011 Share Posted May 21, 2011 (edited) OK, then you can use AutoIt window. expandcollapse popupOpt('WinTitleMatchMode', 1) Opt('WinWaitDelay', 0) $Count = 1 While WinExists('MyUnique' & $Count) $Count += 1 WEnd _MyGUI($Count) $Title = AutoItWinGetTitle() $Count = Number(StringMid($Title, 9, StringInStr($Title, '@') - 8)) While 1 $Count += 1 $hWnd = WinGetHandle('MyUnique' & $Count) If @error Then ExitLoop EndIf $Title = WinGetTitle($hWnd) WinSetTitle(HWnd(StringTrimLeft($Title, StringinStr($Title, '@'))), '', '#' & ($Count - 1)) If @error Then ExitLoop EndIf WinSetTitle($hWnd, '', StringReplace($Title, $Count & '@', ($Count - 1) & '@', 1)) If @error Then ExitLoop EndIf WEnd Func _MyGUI($iIndex) $hWnd = GUICreate('#' & $iIndex, 200, 200) AutoItWinSetTitle('MyUnique' & $Count & '@0x' & Hex($hWnd)) GUISetState() Do Until GUIGetMsg() = -3 GUIDelete() EndFunc ;==>_MyGUI Edited May 21, 2011 by Yashied My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... Link to comment Share on other sites More sharing options...
JAFN Posted May 21, 2011 Author Share Posted May 21, 2011 (edited) My mind is fried now. Can't even figure out who is talking to who now. I'll tackle it fresh in the morning. Thank you. Edited May 21, 2011 by JAFN [size="2"]The second mouse gets the cheese[/size] Link to comment Share on other sites More sharing options...
guinness Posted May 22, 2011 Share Posted May 22, 2011 Yashied, the second Example was very interesting indeed Nice work. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
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