PutinVV Posted January 10, 2019 Share Posted January 10, 2019 Hello, forum users. This code only works on a single window class:CalcFrame If several calculators are open, the code does not accept other calculator windows, only one of them. Although these windows also have CLASS: CalcFrame Why doesn't the code work on them ? How to change the code so that it works on all open windows with CLASS:CalcFrame ? Global $iOnTop_Calc, $hWnd_Calc, $hWnd_Notepad Do ; Wait activated Calc and Notepad If Not $hWnd_Calc Then $hWnd_Calc = WinActive('[CLASS:CalcFrame]') If Not $hWnd_Notepad Then $hWnd_Notepad = WinActive('[CLASS:Notepad]') Sleep(50) Until ($hWnd_Calc And $hWnd_Notepad) While WinExists($hWnd_Notepad) If WinActive($hWnd_Notepad) Then If Not $iOnTop_Calc Then $iOnTop_Calc = WinSetOnTop($hWnd_Calc, '', 1) Else If $iOnTop_Calc And WinSetOnTop($hWnd_Calc, '', 0) Then $iOnTop_Calc = 0 EndIf Sleep(50) WEnd Link to comment Share on other sites More sharing options...
jdelaney Posted January 10, 2019 Share Posted January 10, 2019 WinList('[CLASS:CalcFrame]') Loop through the returned array FrancescoDiMuro 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
PutinVV Posted January 10, 2019 Author Share Posted January 10, 2019 Added WinList to the script. It doesn't work for some reason... Global $iOnTop_Calc, $hWnd_Calc, $hWnd_Notepad Do ; Wait activated Calc and Notepad If Not $hWnd_Calc Then $hWnd_Calc = WinList('[CLASS:CalcFrame]') If Not $hWnd_Notepad Then $hWnd_Notepad = WinList('[CLASS:Notepad]') Sleep(50) Until ($hWnd_Calc And $hWnd_Notepad) While WinExists($hWnd_Notepad) If WinActive($hWnd_Notepad) Then If Not $iOnTop_Calc Then $iOnTop_Calc = WinSetOnTop($hWnd_Calc, '', 1) Else If $iOnTop_Calc And WinSetOnTop($hWnd_Calc, '', 0) Then $iOnTop_Calc = 0 EndIf Sleep(50) WEnd Link to comment Share on other sites More sharing options...
jdelaney Posted January 10, 2019 Share Posted January 10, 2019 Check out the help file on winlist...it returns an array. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window. Link to comment Share on other sites More sharing options...
PutinVV Posted January 10, 2019 Author Share Posted January 10, 2019 jdelaney, I looked at the help. And where exactly in the script to add WinList to the script to work ? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 10, 2019 Share Posted January 10, 2019 (edited) 2 hours ago, PutinVV said: jdelaney, I looked at the help. But you still treat returned arrays from your code as single variables, even if in the Help file is clearely stated: Return Value Returns an array of matching window titles and handles. Remarks If no title and text is given then all top-level windows are returned. The array returned is two-dimensional and is made up as follows: $aArray[0][0] = Number of windows returned $aArray[1][0] = 1st window title $aArray[1][1] = 1st window handle (HWND) $aArray[2][0] = 2nd window title $aArray[2][1] = 2nd window handle (HWND) ... $aArray[n][0] = nth window title $aArray[n][1] = nth window handle (HWND) Put the WinList() at the beginning of your script, and then loop through the array returned to do whatever you want. Edited January 10, 2019 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
PutinVV Posted January 10, 2019 Author Share Posted January 10, 2019 (edited) How to do it - loop through the returned array ? (I just recently started working on AutoIt.) Edited January 10, 2019 by PutinVV Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 10, 2019 Share Posted January 10, 2019 (edited) @PutinVV That's a good question Always from the Help file, you can see that the function WinList() returns a two dimensional array (rows and columns). If you want to obtain the handle of the i-element (i usually stands for Index of the row, used in the array), then you should do something like this: Global $arrWinList = WinList() For $i = 1 To $arrWinList[0][0] Step 1 ConsoleWrite("Window Title = " & $arrWinList[$i][0] & @CRLF & _ "Window Handle = " & $arrWinList[$i][1] & @CRLF) Next If you want to know more about arrays, then take a look at Arrays Wiki and/or at @TheDcoder tutorial Edited January 10, 2019 by FrancescoDiMuro TheDcoder 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
PutinVV Posted January 10, 2019 Author Share Posted January 10, 2019 Added this part to the script. Now when you start the console appears a huge variety of messages. What to do next ? Global $iOnTop_Calc, $hWnd_Calc, $hWnd_Notepad Global $arrWinList = WinList() For $i = 1 To $arrWinList[0][0] Step 1 ConsoleWrite("Window Title = " & $arrWinList[$i][0] & @CRLF & _ "Window Handle = " & $arrWinList[$i][1] & @CRLF) Next Do ; Wait activated Calc and Notepad If Not $hWnd_Calc Then $hWnd_Calc = WinList('[CLASS:CalcFrame]') If Not $hWnd_Notepad Then $hWnd_Notepad = WinList('[CLASS:Notepad]') Sleep(50) Until ($hWnd_Calc And $hWnd_Notepad) While WinExists($hWnd_Notepad) If WinActive($hWnd_Notepad) Then If Not $iOnTop_Calc Then $iOnTop_Calc = WinSetOnTop($hWnd_Calc, '', 1) Else If $iOnTop_Calc And WinSetOnTop($hWnd_Calc, '', 0) Then $iOnTop_Calc = 0 EndIf Sleep(50) WEnd Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 10, 2019 Share Posted January 10, 2019 @PutinVV The example provided above was just an example of what you should do to loop through an array. You should spend more time to understand what do you have instead of ask for Help on here. Everything you need to know to do what you're trying to do, is in the Help file. Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette 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