gnuchu Posted September 28, 2008 Share Posted September 28, 2008 Hi there, Apologies for the newbyish question. I've had a dig around in the forums and the documentation and I can't find any answer to this. I am using Autoit to automatically log into an application. Using code something like: CODEShellExecute ("C:\Program Files\<program>.exe") WinWaitActive("XYZ") Sleep(100) ControlFocus("XYZ","","[Class:TEdit; Instance:2]") ... ... Log in stuff ... This is working fine the first time I run the script. However, I want to use it to open multiple instances of the application XYZ. However, when I use the ControlFocus, when running the script for the second instance, it doesn't always select the new window that is being opened, but the one that is already open. How can I keep unique control over each window that I open? Thanks, gnuchu Link to comment Share on other sites More sharing options...
martin Posted September 28, 2008 Share Posted September 28, 2008 (edited) Hi there, Apologies for the newbyish question. I've had a dig around in the forums and the documentation and I can't find any answer to this. I am using Autoit to automatically log into an application. Using code something like: CODEShellExecute ("C:\Program Files\<program>.exe") WinWaitActive("XYZ") Sleep(100) ControlFocus("XYZ","","[Class:TEdit; Instance:2]") ... ... Log in stuff ... This is working fine the first time I run the script. However, I want to use it to open multiple instances of the application XYZ. However, when I use the ControlFocus, when running the script for the second instance, it doesn't always select the new window that is being opened, but the one that is already open. How can I keep unique control over each window that I open? Thanks, gnuchuTitles for windows are not unique but handles are so you need to find the handle for each window. When you open the first instance it's quite simple because you can just say $inst = 0 $aHandle[$inst] = WinGetHandle("XYZ") After that you could say that if you start another instance and assuming it then becomes the active window $inst += 1 $aHandle[$inst] = WinGetHandle(WinGetTitle("")) To be certain you could use WinList which returns all the windows with a certain title. Then you can check the handles against the list of handles you already have and if there is an extra handle then that must be for the new window. Edited September 28, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
rasim Posted September 28, 2008 Share Posted September 28, 2008 Use a WinGetHandle() function, something like so:ShellExecute ("C:\Program Files\<program>.exe") WinWaitActive("XYZ") $hWnd = WinGetHandle("XYZ") Sleep(100) ControlFocus($hWnd,"","[Class:TEdit; Instance:2]") ... ... Log in stuff ... Link to comment Share on other sites More sharing options...
gnuchu Posted September 28, 2008 Author Share Posted September 28, 2008 Thanks Martin and Rasim. I had seen the window handle in the 'AutoIt Window Info' and thought I could probably use it, but hadn't worked out how. This is exactly what I need. Cheers, John Link to comment Share on other sites More sharing options...
gnuchu Posted September 28, 2008 Author Share Posted September 28, 2008 Just a quick supplemental question to this: I am now using handles to keep track of the different windows. However, when I use WinGetList("myapp") it returns two handles and not one, as expected. Is it normal for an application to have 2 handles? Link to comment Share on other sites More sharing options...
rasim Posted September 29, 2008 Share Posted September 29, 2008 gnuchuHowever, when I use WinGetList("myapp") it returns two handles and not one, as expected. Is it normal for an application to have 2 handles?Show your code. Link to comment Share on other sites More sharing options...
gnuchu Posted September 29, 2008 Author Share Posted September 29, 2008 Well, when I run the following CODE ShellExecute ("C:\Program Files\mysapp\myapp.exe") $wins = WinList("myapp") for $i =1 to $wins[0][0] MsgBox(0, $wins[$i][0], $wins[$i][1]) Next I get two message boxes, each with a different handle for the title 'myapp'. But there's only ever one item in my windows task list. Link to comment Share on other sites More sharing options...
rasim Posted September 29, 2008 Share Posted September 29, 2008 Example with notepad works fine for me: ShellExecute("notepad.exe") WinWait("[CLASS:Notepad]") $wins = WinList("[CLASS:Notepad]") for $i = 1 to $wins[0][0] MsgBox(0, $wins[$i][0], $wins[$i][1]) Next 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