MarcElser Posted April 25, 2015 Share Posted April 25, 2015 Hi All,Wanted to do something very easy with latest Autoit3 and x64 mode enabled on Win 8.1 64bit.Wanted to see if current windows is "Chrome" is active. So here's what I tried#include <MsgBoxConstants.au3> Local $wnd = WinActive("[ACTIVE]") If @error Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the current window handle.") Exit EndIf Local $wndText = WinGetText($wnd) If StringInStr($wndText,"Chrome Legacy Window") Then MsgBox(1,"Info","Chrome found") EndIfThis works. But, why do I have to use "StringInStr" to check $wndText Variable. I also tried normal string comparison like this:If $wndText = "Chrome Legacy Window" ThenIf just doesn't match. I tried with various windows functions like WinGetClassList and so on, all of them need this "StringInStr" workaround. Also this doesn't workIf WinActive("[CLASS:Chrome_RenderWidgetHostHWND]") ThenAlthough I used WinGetClassList on $wnd to get it's class.Do you have any idea what's going on here? Why do the strings not match and why does WinActive Not match the class which I got from WinGetClassList for $wnd? Any Ideas. I'm a bit lost although I'm no newbie with autoit3, but havent used it for quite some time now.Please also forgive me if this question has been asked before, but I couldn't find any hint on FAQ Page or by searching. Link to comment Share on other sites More sharing options...
iamtheky Posted April 25, 2015 Share Posted April 25, 2015 https://www.autoitscript.com/autoit3/docs/functions/AutoItSetOption.htmWinTitleMatchMode of 2 may help. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
jguinch Posted April 25, 2015 Share Posted April 25, 2015 WinGetClassList retuns a list containing the class for each control found in a window.In your case, you want to work with the window's class : maybe _WinAPI_GetClassName could be useful.An another way could be to check the process name of the active window (even if i prefer the window class method in the case of the user renames the exutable).$iActiveWinPid = WinGetProcess("[Active]") If _ProcessName($iActiveWinPid) = "chrome.exe" Then ConsoleWrite("Active Window is chrome") Func _ProcessName($iPid) Local $aProcessList = ProcessList() For $i = 1 To $aProcessList[0][0] If $aProcessList[$i][1] = $iPid Then Return $aProcessList[$i][0] Next Return "" EndFunc Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
mikell Posted April 25, 2015 Share Posted April 25, 2015 (edited) And why not the ultra simple solution suggested by boththose ?Opt("WinTitleMatchMode", -2) If WinActive("chrome") Then ConsoleWrite("Active Window is chrome") Edited April 25, 2015 by mikell Link to comment Share on other sites More sharing options...
jguinch Posted April 25, 2015 Share Posted April 25, 2015 Because I began to answer about WinGetClassList and then I lost my way in the complexity... Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
MarcElser Posted April 25, 2015 Author Share Posted April 25, 2015 And why not the ultra simple solution suggested by boththose ?Opt("WinTitleMatchMode", -2) If WinActive("chrome") Then ConsoleWrite("Active Window is chrome") Well, As the Title of Chrome is always matching the currently active tab. You never know the title especially as the suffix ".... - chrome" is totally missing. So you either have to match via Class or by Text (which is strangely "Chrome Legacy Window"). The only new Idea was to match by PID which might be also a good idea.So, WinTitleMatchMode won't help I guess as it's only for window title by not class or text right?Plus, I still have no answer why a simple "If $wndText = "Chrome Legacy Window" Then ..." doesn't match (where $wndText is the text returned by WinGetText()), same is true for WinGetClasslist, If a print out the string from "WinGetClassList" and make an If statement I have exactly the same problem.If I remember correctly this used to work in earlier windows / autoit versions. Makes it a bit hard if you always have to work with regexes and/or StringInString functions and stuff like that. BTW: is there a builtin function which only strips trailing cr, lf and cr &lf from a string or has it to be done by a regex as well. Link to comment Share on other sites More sharing options...
kylomas Posted April 27, 2015 Share Posted April 27, 2015 BTW: is there a builtin function which only strips trailing cr, lf and cr &lf from a stringYes, StringStripWS... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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