Sign in to follow this  
Followers 0
Guest Jander

WinExists

17 posts in this topic

Hello,

I have a question regarding WinExists. I am trying to match a window - any window - that has the text matching but I don't care about the title.

Example:

$title = ""

$text = "error"

If WinExists($title,$text) Then

EndIf

This will never work. :) Is there a way around this? I've been told that this might have worked in a previous version (2.x). Thank you,

Jander.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This will never work.

Oh? And you've tried this to confirm? You've taken two scripts as follows:

; RunFirst.au3
MsgBox(0, "Title", "error")

and ran it first, then ran:

; RunSecond.au3
If WinExists("", "error") Then MsgBox(4096, "", "Cool")

I mean, in order to say that it will never work, you've done this, right?

Edit: The moral of the story is, don't say something will never work until you've tested it and shown code that tests it and shows it failing.

Edit2: Added title to RunFirst.au3 to ensure no confusion about the title matching.

Edited by Valik

Share this post


Link to post
Share on other sites

What he means to say is that it will never work for his situation.

I am trying to match a window - any window

He means that he doesn't want the active window only, but any window that has that text in it.

@Jander, Since there is no WinGetList yet, there is no way I know of to match in any window, just the active one as illustrated above.

One workaround is to Send("!{TAB}") and loop the winexists to get every window.


Who else would I be?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

What he means to say is that it will never work for his situation.

He means that he doesn't want the active window only, but any window that has that text in it.

@Jander, Since there is no WinGetList yet, there is no way I know of to match in any window, just the active one as illustrated above.

One workaround is to Send("!{TAB}") and loop the winexists to get every window.

<{POST_SNAPBACK}>

You tested my example, right? Right!? No, you didn't, otherwise you would know that I'm not matching the active window. In order to match the active window both the title and text have to be empty (As Larry said). Instead I'm matching the last activated window with the text "error" in it. What I mean by that is, if there are multiple windows that match that, the last one activated (Even if it was 200 windows ago) will be the one that is matched. It doesn't have to be the active window (With focus). Edited by Valik

Share this post


Link to post
Share on other sites

I mean, in order to say that it will never work, you've done this, right?

Edit: The moral of the story is, don't say something will never work until you've tested it and shown code that tests it and shows it failing.

<{POST_SNAPBACK}>

Thank you for the kind answer Valik. :)

However, I did forget a critical part of the initial question. I am trying to match *any window* but the script I have uses the advanced WinTitleMatchMode (4) mode. I noticed a few moments after sending my inquiry that "" refers to the previously activated window, as outlined by this-is-me. :)

I think I've found a (clumsy) workaround however by deactivating WinTitleMatchMode when title is empty because it is not the behavior I seek. Bleah.

Jander.

Share this post


Link to post
Share on other sites

could use DLLCall and "GetWindow"  .. but you will need some learnin...

<{POST_SNAPBACK}>

Yeah, I saw DllCall and it wouldn't be a problem for me to use it but we aren't using AutoIt beta in production. :)

I'll have to look a bit closer at the license to see if we can hack a bit AutoIt ourselves and contribute our changes.

Thanks anyways,

Jander.

Share this post


Link to post
Share on other sites

@Valik, do the words any window have any effect on you? It doesn't matter whether or not the last active window was 200 windows ago. It doesn't matter if it was the last activated window. He wants any window.


Who else would I be?

Share this post


Link to post
Share on other sites

Try this test.

AdlibEnable ("clicker") 
If NOT winexists("test1") Then AutoItWinSetTitle ("test1") 
If AutoItWinGetTitle()="test1" Then 
    tooltip("hi, I am running in the backround",0,0)
    While 1
        sleep(10)
    Wend
Else
    MsgBox(1,"Test1","")
  MsgBox(1,"Test1","testme")
EndIf


Func clicker()
    If winexists("","testme") Then 
        WinSetTitle("","testme","Hi there")
        exit
    EndIf
EndFunc

Basically the first time you run it, it shows a tool tip that it is running and looking for any window with "testme" in the visible text. The second time it will put up two msgboxes. The first one doens't match the criteria, but the second one does and will cause the function to go off and change the title.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Any window also means any window. Or, worded more specifically, the last activated window with matching text is encompassed by the blanket term "any window". I interpret that as meaning it doesn't matter if it was the first window or the last or somewhere between, any window matching text "error" will satisfy the OP's need. That means, any window, focus or not, any window existing in the system that matches the text "error" will be found, and if there are more than one, the match will be against the one that was last active. However, that doesn't matter to the OP since they said any window with text matching "error" would be acceptable.

So, that being said, what the hell are you trying to point out to me? My code does exactly what the OP asked for. Even the OP says that now that they understand what the problem was (WinTitleMatchMode 4 changing how "" is processed).

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

OK. Maybe if I ask a question, I can understand your code better. Does your code take into account if a window is hidden, but still has that text in it? It didn't work that way for me.

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

You have to use Opt(WinDetectHiddenText, 1), I believe.

Share this post


Link to post
Share on other sites

Thanks, Valik.


Who else would I be?

Share this post


Link to post
Share on other sites

You may use this:

Opt("WinTitleMatchMode", 4)

"classname=CLASSNAME"

"handle=HANDLE"

"active"

"last" or ""

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

@this-is-me: just curious how you could not see what Valik's code was doing? It was plain to me that WinExists searches for any window, and if it's plain to me, it should be plain to everyone =-o

Edit:

also, @valik How come you put in ;RunFirst.au3? I don't understand what that does.

Edited by the_lord_mephy

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

I was blinded by the fact that hidden windows did not apply unless windetecthiddentext was turned on.

How come you put in ;RunFirst.au3? I don't understand what that does.

If you look carefully in the helpfile, you will see that a ; is a comment character. That means that it does absolutely NOTHING and only serves the purpose to show what you might name the file in that code.

Who else would I be?

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

I know but what i was saying was why did he include that code in a whole.

Edit:

Oooh I get it, you wanted to have a window exist with the text "error" in it.

Edited by the_lord_mephy

My site for HTML Help :)[quote name='Valik' date='Oct 15 2004, 12:29 PM']Maybe nobody is an "elite uber-coder" like me because thinking is a capital offense in today's online-world?[right][snapback]36427[/snapback][/right][/quote]

Share this post


Link to post
Share on other sites

It gives a starting point incase there was no window that already existed with the text "error" in it.


Who else would I be?

Share this post


Link to post
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
Sign in to follow this  
Followers 0