Jump to content

WinGetState not working with any window


blahdaze
 Share

Recommended Posts

Longtime AutoIt-er, first time poster.

I'd like to add a feature to a larger app that I have, using the WinGetState function. To "play" with the functionality of the function I wrote the following applet <more>:

CODE

Opt("WinTitleMatchMode",4)

$WindowToObserveTitle = InputBox("Window title to observe:","Please enter the beginning of the window title to observe:")

While 1

$SCState = WinGetState($WindowToObserveTitle,"")

Select

Case $SCState = 1 ;Window exists

ToolTip($WindowToObserveTitle & " window exists",1,1)

Case $SCState = 2 ;Window is visible

ToolTip($WindowToObserveTitle & " window is visible",1,1)

Case $SCState = 4 ;Window is enabled

ToolTip($WindowToObserveTitle & " window is currently enabled",1,1)

Case $SCState = 8 ;Window is active

ToolTip($WindowToObserveTitle & " window active",1,1)

Case $SCState = 16 ;Window is minimized

ToolTip($WindowToObserveTitle & " window minimized",1,1)

Case $SCState = 32 ;Window is maximized

ToolTip($WindowToObserveTitle & " window maximized",1,1)

Case Else

ToolTip($WindowToObserveTitle & " window status unknown",1,1)

EndSelect

WEnd

What I don't get is that in the larger application I do stuff with window titles all the time. I've tried changing the WinTitleMatchMode to all four settings. So what am I missing?

If I can get this working, I can begin working on getting my larger toolbar app to follow around the window of the application it's used with. Perhaps someone has a better idea altogether on how to accomplish this?

Hugs,

Blah

Link to comment
Share on other sites

  • Moderators

Your code doesn't move on past the Input box code until you've actually pressed ok/cancel, so getting its state from one script isn't going to happen like this.

An alternative could be to do the InputBox separate with something like /AutoIt3ExecuteLine, or if you need the value from InputBox then /AutoIt3ExecuteScript

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

Longtime AutoIt-er, first time poster.

I'd like to add a feature to a larger app that I have, using the WinGetState function. To "play" with the functionality of the function I wrote the following applet <more>:

CODE

Opt("WinTitleMatchMode",4)

$WindowToObserveTitle = InputBox("Window title to observe:","Please enter the beginning of the window title to observe:")

While 1

$SCState = WinGetState($WindowToObserveTitle,"")

Select

Case $SCState = 1 ;Window exists

ToolTip($WindowToObserveTitle & " window exists",1,1)

Case $SCState = 2 ;Window is visible

ToolTip($WindowToObserveTitle & " window is visible",1,1)

Case $SCState = 4 ;Window is enabled

ToolTip($WindowToObserveTitle & " window is currently enabled",1,1)

Case $SCState = 8 ;Window is active

ToolTip($WindowToObserveTitle & " window active",1,1)

Case $SCState = 16 ;Window is minimized

ToolTip($WindowToObserveTitle & " window minimized",1,1)

Case $SCState = 32 ;Window is maximized

ToolTip($WindowToObserveTitle & " window maximized",1,1)

Case Else

ToolTip($WindowToObserveTitle & " window status unknown",1,1)

EndSelect

WEnd

What I don't get is that in the larger application I do stuff with window titles all the time. I've tried changing the WinTitleMatchMode to all four settings. So what am I missing?

If I can get this working, I can begin working on getting my larger toolbar app to follow around the window of the application it's used with. Perhaps someone has a better idea altogether on how to accomplish this?

A couple of points.

The value returned by WinGetState() is a combination of the available values you need to BitAnd() it to check which states are current

Calling WinGetState() when the tooltip is visible seems to always return a value of 7 Exist, Visible and Active?

One thing that does not seem to work correctly is the minimised is not set when a window is minimised to the taskbar in Win XP

I've ammended your code I now works for me

Opt("WinTitleMatchMode", 4)

$WindowToObserveTitle = InputBox("Window title to observe:", "Please enter the beginning of the window title to observe:")

While 1
    ToolTip("")
    $SCState = WinGetState($WindowToObserveTitle, "")
    Select
        Case BitAND($SCState,32) = 32 ;Window is maximized 
            ToolTip($WindowToObserveTitle & " window maximized", 1, 1)
        Case BitAND($SCState,16) = 16 ;Window is minimized
            ToolTip($WindowToObserveTitle & " window  is minimized", 1, 1)
        Case BitAND($SCState,8) = 8 ;Window is enabled
            ToolTip($WindowToObserveTitle & " window is currently enabled", 1, 1)
        Case BitAND($SCState,4) = 4 ;Window is active
            ToolTip($WindowToObserveTitle & " Window is active", 1, 1)
        Case BitAND($SCState,2) = 2 ;Window is visible
            ToolTip($WindowToObserveTitle & " window is visible", 1, 1)
        Case BitAND($SCState,1) = 1 ;Window exists
            ToolTip($WindowToObserveTitle & " window exists", 1, 1)
        Case Else
            ToolTip($WindowToObserveTitle & " window status unknown", 1, 1)
    EndSelect
    Sleep(200)
WEnd
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Link to comment
Share on other sites

  • Moderators

A couple of points.

The value returned by WinGetState() is a combination of the available values you need to BitAnd() it to check which states are current

Calling WinGetState() when the tooltip is visible seems to always return a value of 7 Exist, Visible and Active?

One thing that does not seem to work correctly is the minimised is not set when a window is minimised to the taskbar in Win XP

I've ammended your code I now works for me

Opt("WinTitleMatchMode", 4)

$WindowToObserveTitle = InputBox("Window title to observe:", "Please enter the beginning of the window title to observe:")

While 1
    ToolTip("")
    $SCState = WinGetState($WindowToObserveTitle, "")
    Select
        Case BitAND($SCState,32) = 32 ;Window is maximized 
            ToolTip($WindowToObserveTitle & " window maximized", 1, 1)
        Case BitAND($SCState,16) = 16 ;Window is minimized
            ToolTip($WindowToObserveTitle & " window  is minimized", 1, 1)
        Case BitAND($SCState,8) = 8 ;Window is enabled
            ToolTip($WindowToObserveTitle & " window is currently enabled", 1, 1)
        Case BitAND($SCState,4) = 4 ;Window is active
            ToolTip($WindowToObserveTitle & " Window is active", 1, 1)
        Case BitAND($SCState,2) = 2 ;Window is visible
            ToolTip($WindowToObserveTitle & " window is visible", 1, 1)
        Case BitAND($SCState,1) = 1 ;Window exists
            ToolTip($WindowToObserveTitle & " window exists", 1, 1)
        Case Else
            ToolTip($WindowToObserveTitle & " window status unknown", 1, 1)
    EndSelect
    Sleep(200)
WEnd
What do you mean it works for you?

Since when does the return value of InputBox() give you a handle?

Edit:

I see what you are saying now... I saw that and totally got thrown off (Using the input info to get the title <_< )

Edited by SmOke_N

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

A couple of points.

The value returned by WinGetState() is a combination of the available values you need to BitAnd() it to check which states are current

Calling WinGetState() when the tooltip is visible seems to always return a value of 7 Exist, Visible and Active?

One thing that does not seem to work correctly is the minimised is not set when a window is minimised to the taskbar in Win XP

I've ammended your code I now works for me

Opt("WinTitleMatchMode", 4)

$WindowToObserveTitle = InputBox("Window title to observe:", "Please enter the beginning of the window title to observe:")

While 1
    ToolTip("")
    $SCState = WinGetState($WindowToObserveTitle, "")
    Select
        Case BitAND($SCState,32) = 32 ;Window is maximized 
            ToolTip($WindowToObserveTitle & " window maximized", 1, 1)
        Case BitAND($SCState,16) = 16 ;Window is minimized
            ToolTip($WindowToObserveTitle & " window  is minimized", 1, 1)
        Case BitAND($SCState,8) = 8 ;Window is enabled
            ToolTip($WindowToObserveTitle & " window is currently enabled", 1, 1)
        Case BitAND($SCState,4) = 4 ;Window is active
            ToolTip($WindowToObserveTitle & " Window is active", 1, 1)
        Case BitAND($SCState,2) = 2 ;Window is visible
            ToolTip($WindowToObserveTitle & " window is visible", 1, 1)
        Case BitAND($SCState,1) = 1 ;Window exists
            ToolTip($WindowToObserveTitle & " window exists", 1, 1)
        Case Else
            ToolTip($WindowToObserveTitle & " window status unknown", 1, 1)
    EndSelect
    Sleep(200)
WEnd

Bowmore, it doesn't work for me, saying that the window is always active....

[ ]s

NomadRJ

Link to comment
Share on other sites

Bowmore, it doesn't work for me, saying that the window is always active....

[ ]s

NomadRJ

It's working for me although I did have active and enabled transposed. Maybe it was not the best script to demonstrate how WinGetState() works so I've rewriten the code so that the tooltip displays ALL the states of the window with the title specified in the input box. Try running this and playing around with the window.

Opt("WinTitleMatchMode", 4)

$WindowToObserveTitle = InputBox("Window title to observe:", "Please enter the beginning of the window title to observe the status of:")

Dim $Msg = ""
While 1
    ToolTip("")
    $SCState = WinGetState($WindowToObserveTitle, "")
    $Msg = " window "

    If BitAND($SCState,1) = 0 Then $Msg &= " does not exist"
    If BitAND($SCState,1) = 1 Then $Msg &= " exists"
    If BitAND($SCState,2) = 2 Then $Msg &= " and is visible"
    If BitAND($SCState,4) = 4 Then $Msg &= " and is enabled"
    If BitAND($SCState,8) = 8 Then $Msg &= " and is active"
    If BitAND($SCState,16) = 16 Then $Msg &= " and is minimized"
    If BitAND($SCState,32) = 32 Then $Msg &= " and is maximized"
    If $Msg = " window " Then $Msg = " window status is unknown"
    
    ToolTip($WindowToObserveTitle & $Msg, 1, 1)
    Sleep(500)
WEnd

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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