Jump to content

Ugh, this should be easy - How to get a windows Handle when a user clicks on it


Recommended Posts

I hope I am just having a brain fart and this is actually easy. Here is the issue I am having. I am trying to simulate a Live Meeting between two people. This is so I can test more quickly after weekly maintenance that everything is functioning correctly still. For testing purposes, both the Presenter and the Attendee are on the same computer. The tester just has 2 LM windows open. I need to get the Handle of each window and know which one is which. Currently, I have a msgbox popup that tells the test to click the Presenter window, then Yes on msgbox. Then a new msgbox pops up telling the tester to click the Attendee LM window, then Yes on the msgbox. While this works 90% of the time, occassionally the code seems to grab the msgbox handle instead. The $size variable at the end often ends up being an empty array. Any suggestions would be appreciated.

AutoItSetOption("WinTitleMatchMode", 4)

MsgBox(4,"Click on Presenter window","Click Yes once you have made the Presenter window the active window.")

sleep(500)

$presenterHWND=WinGetHandle("[Active]")

MsgBox(4,"Click on Attendee window","Click Yes once you have made the Attendee window the active window.")

sleep(500)

$attendeeHWND=WinGetHandle("[Active]")

$size=WinGetPos($presenterHWND)

Link to comment
Share on other sites

I'm surprised you get the LM window handle at all. Once you click the msgbox, that becomes the active window, so unless the user clicks the LM window, or it automatically becomes the active window, then the msgbox is probably what you're going to get. You only sleep the script for 1/2 a second, which may not be enough time for the msgbox window to close before the other window becomes active again.

If the 2 windows have different titles, then you can use WinWaitActive to find out which is which and dispense with the message box.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Developers

It is not that surprising as you click the window you want the handle of which will change the zorder and then click the msgbox.

The msgbox closes and the previous clicked window becomes active.

Could try the longer sleep to see if that works.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Yeah, that way seemed too flaky, even when I extended the sleep. Thanks for helping me think this one through. Ended up getting the handle when just one was open through winlist(), and then getting the next one after through winlist() too, just looped until had 2 with different handles. Works now. Thanks again.

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