Jump to content

Recommended Posts

Posted (edited)

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
Posted

Lar, I actually tried that...no go...thanks.

PsaltyDS, You've confused me a little. You gave the example, but then you say it is like the ElseIf chain.?.? I need to see which of 20 possible windows has a value of 15.

  • Moderators
Posted

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.

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