OneCardShy Posted November 10, 2021 Share Posted November 10, 2021 For years I have used WinActivate and WinWaitActive to run scripts against an application. I use them from time to time throughout the script because other environment hazards (pop-ups, etc.) can snatch focus away from the main application. Due to a recent change in the application, the Window title changes every time it runs an operation, and some of those occasional hazards can also change the Window's title. There is only one instance of the application running. Is there a way that I can set focus on that application, no matter what the Window Title happens to be at that moment?? There is zero standardization per screen (hidden text) and no common threads in the window naming pattern. I just need to say, "Yes... that program. Whatever you want to call it, give it the focus." Thank you for what I expect to be something obvious and overlooked. Link to comment Share on other sites More sharing options...
mikell Posted November 10, 2021 Share Posted November 10, 2021 I can imagine 2 ways to skin this cat - use _WinAPI_EnumProcessWindows to get the visible window associated to the process - use a regex in the 'title' param of the WinActivate, this allows changes in the title and could work as long as there is a constant part in the title Link to comment Share on other sites More sharing options...
OneCardShy Posted November 10, 2021 Author Share Posted November 10, 2021 For your second solution, I used to deal with window title changes with WinTitleMatchMode ... but there is no longer any constant. (That is actually the change in the target application - the loss of a constant in the title.) I am not familiar with have not explored "_WinAPI_EnumProcessWindows" ... I will go and quick study now. Thank you for the direction to look! Link to comment Share on other sites More sharing options...
JockoDundee Posted November 10, 2021 Share Posted November 10, 2021 3 hours ago, mikell said: - use a regex in the 'title' param of the WinActivate You sly dog Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
junkew Posted November 11, 2021 Share Posted November 11, 2021 One time get the hwnd and then winactivate(hwnd) https://www.autoitscript.com/autoit3/docs/intro/windowsadvanced.htm https://www.autoitscript.com/autoit3/docs/functions/WinActivate.htm https://www.autoitscript.com/autoit3/docs/functions/WinGetHandle.htm FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets 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