Jump to content

Differentiating between Windows


gnuchu
 Share

Recommended Posts

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:

CODE
ShellExecute ("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

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:

CODE
ShellExecute ("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

Titles 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 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

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

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

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...