Jump to content

The reaction to the activity of another window is for multiple Windows.


PutinVV
 Share

Recommended Posts

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

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

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 by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@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 by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

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

@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:

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...