Jump to content

Recommended Posts

Posted

My counter counts from 0 on, if it finds any Notepad window opened, but it counts double (if 2 windows are opened), triple (if 3 windows are opened)..., instead of 1, 2, 3... Any suggestion? 

#include <Array.au3>

$count = 0

While 1
$aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))

For $i=1 To $aWindows[0][0]

   $iWndState =  WinGetState($aWindows[$i][1])
   $count += 1

   ToolTip("count = " & $count, 0, 0, "state = " & $iWndState)

Next
   Sleep(1000)
WEnd

 

Posted

Technically you're only ever seeing the last item in the array and you're counting how many times you loop not the number of Windows example if you use the following you'll see the state for each window.

For $i = 1 To $aWindows[0][0]
    $iWndState =  WinGetState($aWindows[$i][1])
    $count += 1
    ToolTip("count = " & $count, 0, 0, "state = " & $iWndState)
    Sleep(1000)
Next

 

Posted

You can check to see if a new notepad window using something like the following:

#include <Array.au3>

Global $aWindows, $iWndState, $iWinCount = 0

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then
        $iWinCount = $aWindows[0][0]
        For $i = 1 To $aWindows[0][0]
            $iWndState =  WinGetState($aWindows[$i][1])
            ToolTip("count = " & $i, 0, 0, "state = " & $iWndState)
            Sleep(1000)
        Next
    EndIf
    Sleep(1000)
WEnd

 

Posted
1 hour ago, Subz said:

You can check to see if a new notepad window using something like the following:

#include <Array.au3>

Global $aWindows, $iWndState, $iWinCount = 0

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then
        $iWinCount = $aWindows[0][0]
        For $i = 1 To $aWindows[0][0]
            $iWndState =  WinGetState($aWindows[$i][1])
            ToolTip("count = " & $i, 0, 0, "state = " & $iWndState)
            Sleep(1000)
        Next
    EndIf
    Sleep(1000)
WEnd

 

With this code, count is always 1.

Posted (edited)

It works fine for me although it would always keep the last Tooltip if all Notepad windows are closed since $i starts at 1 not 0.  You would just need to add an "if" statement as follows.  If no windows are found it will return count = 0 and state = -, if you open multiple notepad instances it will display the last window state in the loop.

Global $aWindows, $iWndState, $iWinCount = 999

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then
        $iWinCount = $aWindows[0][0]
        If $iWinCount = 0 Then ContinueLoop ToolTip("count = 0", 0, 0, "state = -")
        For $i = 1 To $aWindows[0][0]
            $iWndState =  WinGetState($aWindows[$i][1])
            ToolTip("count = " & $i, 0, 0, "state = " & $iWndState)
            Sleep(1000)
        Next
    EndIf
    Sleep(1000)
WEnd

 

Edited by Subz
Posted (edited)

With your code "count" is always 1 if one window, if two it count just 1, 2, if three it counts just 1, 2, 3.

Edited by itauto3
Posted

I want the count to normally count, like a clock, 1, 2, 3... But, when new Notepad window opens, it should start from 0 and again count like a clock, to n.

Posted

Whats the point of the For/Next loop as the $iWndState will always be for the last window in the loop?

I think this is what you're after.

Global $aWindows, $iWndState, $iWinCount = 999, $iCount

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then
        $iCount = 0
        $iWinCount = $aWindows[0][0]
        Switch $iWinCount
            Case 0
                $iWndState = "-"
            Case Else
                $iWndState =  WinGetState($aWindows[$aWindows[0][0]][1])
        EndSwitch
    EndIf
    Sleep(1000)
    ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState)
    $iCount += 1
WEnd

 

Posted (edited)
$count = 0
$result = 0
.
.
.
.
$result = $result & ", " & $count += 1

Is that maybe what you are after?

That should give you - 0, 1, 2, 3, etc.

If you don't want 0, just trim it or adjust the code with an ElseIf.

Edited by TheSaint

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Posted
21 hours ago, Subz said:

Whats the point of the For/Next loop as the $iWndState will always be for the last window in the loop?

I think this is what you're after.

Global $aWindows, $iWndState, $iWinCount = 999, $iCount

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then
        $iCount = 0
        $iWinCount = $aWindows[0][0]
        Switch $iWinCount
            Case 0
                $iWndState = "-"
            Case Else
                $iWndState =  WinGetState($aWindows[$aWindows[0][0]][1])
        EndSwitch
    EndIf
    Sleep(1000)
    ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState)
    $iCount += 1
WEnd

 

The state of the window is always 15?

Posted

You seem to want to be spoon fed the answer, it would only take a couple of changes to that code to get what you want, hint make the if statement one line to equal $iCount and remove the EndIf.

Posted
On 17. 1. 2019 at 12:45 PM, Subz said:

Whats the point of the For/Next loop as the $iWndState will always be for the last window in the loop?

I think this is what you're after.

Global $aWindows, $iWndState, $iWinCount = 999, $iCount

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then
        $iCount = 0
        $iWinCount = $aWindows[0][0]
        Switch $iWinCount
            Case 0
                $iWndState = "-"
            Case Else
                $iWndState =  WinGetState($aWindows[$aWindows[0][0]][1])
        EndSwitch
    EndIf
    Sleep(1000)
    ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState)
    $iCount += 1
WEnd

Do I have to replace existing if statement or add a new one?

 

Posted (edited)
Global $aWindows, $iWndState, $iWinCount = 999, $iCount

While 1
    $aWindows = WinList(("[REGEXPTITLE:(?i)(.*Notepad.*)]"))
    If $iWinCount <> $aWindows[0][0] Then $iCount = 0
    $iWinCount = $aWindows[0][0]
    Switch $iWinCount
        Case 0
            $iWndState = "-"
        Case Else
            $iWndState =  WinGetState($aWindows[$aWindows[0][0]][1])
    EndSwitch
    ToolTip("count = " & $iCount, 0, 0, "state = " & $iWndState)
    Sleep(1000)
    $iCount += 1
WEnd

 

Edited by Subz
  • 2 weeks later...
Posted

Can someone help me with this? Window state should be changing - the best would be, if it would track the state of active window (that is currently in front of others - among all Notepad windows).

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
×
×
  • Create New...