Jump to content

Detecting child windows (and closing them)


Recommended Posts

I am writing an application that interfaces with a piece of wrestling tourney software to export data regularly. I can use winmenuselectitem to access the menu item that I need, but child windows block input to the parent window until they are closed. I have been looking all over the forums and racking my brain, and I can't figure out a way to detect if any windows are open and close them so that the data can be exported.

winactivate will activate the window, but any commands aren't sent until the child windows are closed.

attached is a screenshot of the window info for both windows.(the window info overlaps its respective window) (the software is TWT by pes-sports)

http://imgbucket.info/photo/n1oozxe6s/Untitled.jpg

Thank you in advance, and if you need any more information let me know.

Daniel

Link to comment
Share on other sites

  • Moderators

Hi DanielF847. Do you want the second window closed any time that it pops up? If so, check out AdLibRegister in the Help file. Something like this will check for the existence of that window every 250ms and close it if it is detected.

AdlibRegister("SelectMatch")
Func SelectMatch()
    If WinActive("Select Match") Then
        WinClose("Select Match")
    EndIf
EndFunc

If you're looking for something that closes it only when you're performing a certain function, you can still use AdLibRegister, you just need to work in the logic for your action.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Thank you for your reply JLogan3of13

The issue is that there are various windows that are open. windows like "Select Match" "Change Result" "Select Weight ..." etc. maybe 15-20 possibilities. and then I have to cope with the existence of their own child windows.

Also, I am getting better at scripting and realize that I don't want my script to rely on whether or not a window is active at any given time. This is the basic premise of my application...

TWT has an export format that allows for things like publishing brackets and results to the web. frustratingly enough, it does not automatically update. updating takes time, so I would like it to happen transparently so the script should

Wait for a specified amount of time (say 5 minutes)

GuiWindow opens asking if I would like to update

The window contains a countdown and a "postpone" key

if the countdown reaches zero (like I'm not at the computer) then the software updates

To update, the script has to access the publish menu in "The Wrestling Tourney" window

I would like the script to be robust enough to know whether or not that would work and close other child windows if it would not. (if they are blocking input)

because it is frustrating to get back to my computer during the tournament and find that the script hasn't updated because you had a bracket open

Then, of course repeat (updating in another 5 minutes)

if someone could just point me in the right direction, I'd be happy to turn this into a reuseable code snippet, but I'm totally lost on how to accomplish this (while making it robust enough that I won't come back to a tourney thats waiting to update)

Link to comment
Share on other sites

Do a search for the function _ProcessGetChildren, it might be of some use to get the PID of the child windows so that you can close them when they pop up.

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

_processgetchildren didn't exactly help, but it did get me to the answer.

I ended up using a user created code snippet (function _ProcessGetWindow($pid) ) to find all windows for a process, and then eliminated all of the windows that I did not want. (up until the first one IE the parent)

_processGetWindow($pid) returns an array where array[0] = the number of windows and array[1] to array[number of windows] returns the handle of its respective window. array[1] is always the topmost window. so I wrote a function to eliminate of the top windows until a certain number are left...

a little sloppy but it gets the job done for my purposes.

#include <array.au3>
Func closeChildren($pid, $leaveopen)
$window = _ProcessGetWindow($pid)
for $i = 1 To $window[0]-$leaveopen
  WinClose($window[$i])
Next
EndFunc

to use it, make sure to head over to the thread below and grab the code for _processgetwindow from RulerOf

I think this thread can be close now, Thanks guys!

(and thanks BrewMan for pointing me in the right direction)

Daniel

PS. Thanks to RulerOf for providing the _ProcessGetWindow($pid, $p_ReturnBestGuess = False ) function

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