Jump to content

Numerous WinGetState


Champak
 Share

Recommended Posts

So I have numerous WinGetStates in an IF condition:

If WinGetState() = 15 Then
;
ElseIf WinGetState() = 15 Then
;
ElseIf WinGetState() = 15 Then
;
ElseIf WinGetState() = 15 Then
...........
EndIf

The problems is towards the end it gets slow, takes longer to get to the ElseIf towards the end....obviously I guess. Is there a faster way to do this?

Link to comment
Share on other sites

So I have numerous WinGetStates in an IF condition:

If WinGetState() = 15 Then
;
ElseIf WinGetState() = 15 Then
;
ElseIf WinGetState() = 15 Then
;
ElseIf WinGetState() = 15 Then
...........
EndIf

The problems is towards the end it gets slow, takes longer to get to the ElseIf towards the end....obviously I guess. Is there a faster way to do this?

Use a variable so you don't repeat the WinGetState():
$iState = WinGetState(WinGetHandle("[ACTIVE]"))
Select
    Case BitAND($iState, 32)
        ConsoleWrite("Maximized" & @LF)
    Case BitAND($iState, 16)
        ConsoleWrite("Minimized" & @LF)
    Case BitAND($iState, 8)
        ConsoleWrite("Active" & @LF)
    Case BitAND($iState, 4)
        ConsoleWrite("Enabled" & @LF)
    Case BitAND($iState, 2)
        ConsoleWrite("Visible" & @LF)
    Case BitAND($iState, 1)
        ConsoleWrite("Exists" & @LF)
EndSelect

The problem here is that multiple bits are set in the window state, so once it hits on Maximized for example it will not go on to check Visible. But this is consistent with your ElseIf chain, anyway.

:(

Did you mean to check against the same value over and over? What's the point?

:mellow:

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • Moderators

Well you can only have one active window, so store your titles/handles in an array that you are looking for, do a WinGetTitle("")/WinGetHandle("") once, then loop through the 20 window titles/handles you have stored, if the active window matches one of them, then you do 1 WinGetState($h_wnd, "", 7), so all in all, you only called window functions twice.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...