Jump to content

winactive?


Recommended Posts

If the window is not active does not mean that it does not exist. So perhaps WinGetState() may help you.

Here is an example of WinGetState()

; use notepad as an example
$pid = Run('Notepad')
If WinWait('Untitled', '', 5) Then
    While 1
        ; output window state to output pane of editor
        ConsoleWrite(_IsWinState('Untitled') & @CRLF)
        ; if error then window not exists or just use WinExists() instead
        If _IsWinState('Untitled') And @error Then
            SplashTextOn(@ScriptName, 'Window not exists', Default, 80)
            Sleep(2000)
            SplashOff()
            ExitLoop
        EndIf
        ; check if visible and not active and message if true
        If _IsWinState('Untitled', '', 'visible') And Not _IsWinState('Untitled', '', 'active') Then
            SplashTextOn(@ScriptName, 'Window is visible and not active', Default, 80)
            Sleep(1000)
            SplashOff()
        EndIf
        Sleep(1000)
    WEnd
EndIf


Func _IsWinState($title, $text = '', $state_check = '')
    Local $winstate, $state_add = '|'
    If $state_check Then $state_check = '|' & $state_check & '|'
    ; get the state of window
    $winstate = WinGetState($title, $text)
    If @error Then Return SetError(1, 0, '|error|')
    ; collect window state information
    If BitAND($winstate, 32) Then $state_add &= 'maximized|'
    If BitAND($winstate, 16) Then $state_add &= 'minimized|'
    If BitAND($winstate, 8) Then $state_add &= 'active|'
    If BitAND($winstate, 4) Then $state_add &= 'enabled|'
    If BitAND($winstate, 2) Then $state_add &= 'visible|'
    If BitAND($winstate, 1) Then $state_add &= 'exists|'
    ; just return the delimited string if not $state_check
    If Not $state_check Then Return $state_add
    ; return true if state is in the delimited string
    If StringInStr($state_add, $state_check) Then Return True
    Return ''
EndFunc
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...