mro2 Posted April 11, 2011 Share Posted April 11, 2011 Guys, consider the following script #include <Constants.au3> Func WinExistsExact($title, $text="") MsgBox( 0, "Before Setting", AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHEXACT )) $res = WinExists($title, $text) MsgBox( 0, "After Setting", AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHSTART )) MsgBox(0, "res", $res) Return $res EndFunc If WinExistsExact("XXX") Then MsgBox(0, "aaa", "Test True") EndIf Now I have a window called "XXX (bla)". Why does the test work? If I use If WinExistsExact("XXX (bla)") Then it does not return true... (The goal is having a function that allows to directly check the *exact* window title) Link to comment Share on other sites More sharing options...
saywell Posted April 11, 2011 Share Posted April 11, 2011 (edited) Should be Opt("WinTitleMatchMode", 3) for exact match. William Edited April 11, 2011 by saywell Link to comment Share on other sites More sharing options...
mro2 Posted April 11, 2011 Author Share Posted April 11, 2011 AFAIK that is the same thing as my AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHEXACT ) The debug output that you see in my example indicates so too. Can you try with a space in the Window's title name? The culprit must be somewhere. Link to comment Share on other sites More sharing options...
saywell Posted April 11, 2011 Share Posted April 11, 2011 According to the helpfile, WinTitlematch mode takes a numeric parameter. WinTitleMatchMode Alters the method that is used to match window titles during search operations. 1 = Match the title from the start (default) 2 = Match any substring in the title 3 = Exact title match 4 = Advanced mode, see Window Titles & Text (Advanced) -1 to -4 = force lower case match according to other type of match. from the examples: Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase William Link to comment Share on other sites More sharing options...
mro2 Posted April 11, 2011 Author Share Posted April 11, 2011 (edited) I use the symbolic names #include <Constants.au3>: ; Alters the method that is used to match window titles Global Const $OPT_MATCHSTART = 1 ; Match the title from the start (default) Global Const $OPT_MATCHANY = 2 ; Match any substring in the title Global Const $OPT_MATCHEXACT = 3 ; Match the title exactly Global Const $OPT_MATCHADVANCED = 4 ; Use advanced window matching (deprecated) The option is set correctly as the MsgBox output in the code shows. Edited April 11, 2011 by mro2 Link to comment Share on other sites More sharing options...
saywell Posted April 11, 2011 Share Posted April 11, 2011 Your function returns $res, which should equal unity for a match. Where do you test this. If WinExistsExact("XXX") Then MsgBox(0, "aaa", "Test True") EndIf should perhaps be $test= WinExistsExact("XXX") If $test = 1 Then MsgBox(0, "aaa", "Test True") EndIf William Link to comment Share on other sites More sharing options...
mro2 Posted April 11, 2011 Author Share Posted April 11, 2011 The output of MsgBox(0, "res", $res) inside WinExistsExact is already 1 when it should not be -- i.e. when I have a window title called "XXX (abc)" but when I use WinExistsExact("XXX"), MsgBox(0, "res", $res) says 1 whereas it should say 0. Link to comment Share on other sites More sharing options...
saywell Posted April 11, 2011 Share Posted April 11, 2011 Why complicate the script with these nested msgbox statements? The last bit, that calls the function, is able to display the result. This works for me - I have a window with full title of "Novell GroupWise - Mailbox" open at the moment #include <Constants.au3> $title = "Novell GroupWise - Mailbox" $title2 = "Novell GroupWise " $text="" $fullTest = WinExistsExact($title, $text) $partTest = WinExistsExact($title2, $text) Func WinExistsExact($title, $text) AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHEXACT ) $res = WinExists($title, $text) AutoItSetOption( "WinTitleMatchMode", $OPT_MATCHSTART ) MsgBox(0, "res", $res) Return $res EndFunc If $fullTest = 1 Then MsgBox(0, "Full", "Test True") Else MsgBox(0, "Full", "Test False") EndIf If $partTest = 1 Then MsgBox(0, "Partial", "Test True") Else MsgBox(0, "Partial", "Test False") EndIf William Link to comment Share on other sites More sharing options...
mro2 Posted April 11, 2011 Author Share Posted April 11, 2011 This works here too for a similar example. However, I bet that if you have a title containing parentheses and used $title = "Novell GroupWise ( Mailbox" $title2 = "Novell GroupWise" then it would return True twice. Must be the parentheses then. Link to comment Share on other sites More sharing options...
saywell Posted April 11, 2011 Share Posted April 11, 2011 I made a text doc called abc (.txt and opened it in notepad. Testing against $title = "abc (.txt - Notepad" $title2 = "abc (.txt" worked as expected - full match = 1, partial = 0 So there must be something wrong elsewhere in your script. I'd suggest consolewrites or simple message boxes at various steps along the way to see what's going on. William Link to comment Share on other sites More sharing options...
mro2 Posted April 11, 2011 Author Share Posted April 11, 2011 (edited) Could you also try that with $title = "abc" i.e. trying a full match with a partial string plz Edited April 11, 2011 by mro2 Link to comment Share on other sites More sharing options...
saywell Posted April 11, 2011 Share Posted April 11, 2011 As expected, partial string fails to make a full match - but you could have discovered that for yourself... William Link to comment Share on other sites More sharing options...
mro2 Posted April 12, 2011 Author Share Posted April 12, 2011 (edited) Ok... but I swear that with an inhouse app the *full* match returns true even if I only match the beginning of the string, i.e. the window title is "aaa (abc) XXX (def)" then a full match using "aaa" also works (return true / activates the window / whatever). That is indeed not the case if I try with Notepad... You will say "must be the app then". Ok, but what exactly? Strange characters in the title maybe? Edited April 12, 2011 by mro2 Link to comment Share on other sites More sharing options...
saywell Posted April 12, 2011 Share Posted April 12, 2011 What does the autoit window info tool make of the title? William Link to comment Share on other sites More sharing options...
mro2 Posted April 14, 2011 Author Share Posted April 14, 2011 What does the autoit window info tool make of the title? The actual window that I want to use is shown correctly (the long string) and even when I use Opt( "WinTitleMatchMode", 3 ) WinActivate("short_string") even though it does not *exactly* match "short_string" but "short_string (with more stuff)" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now