views:

91

answers:

2

I have a Python program (PP) that loads another Program(AP) via COM, gets its window handle and sets it to be the PP parent.

This works pretty well except that I can't control that AP still has their [X] button available in the top left corner. Since this is a pretty obvious place for the user to close when they are done with the program, I tried this and it left the PP in the Task Manager running, but not visible with no possible way to kill it other than through Task Manager. Any ideas on how to handle this? I expect it to be rather Common that the user closes in this manner.

Thanks!

+1  A: 

How's PP's control flow? If it's event-driven it could get appropriate events upon closure of that parent window or termination of that AP process; otherwise it could "poll" to check if the window or process are still around.

Alex Martelli
It's kinda hard to say; communication between the two is pretty much a one way street. PP tells AP what to do and asks for information back at the appropriate time, but AP is a GUI so Polls might get blocked through COM, so I'm not sure I want to do that constantly. In python if a parent is closed, should that trigger an event with the child?
Fry
Thanks for the advice, I polled the api instead of AP and that seems to work very well. Thanks for starting me down a working path :)
Fry
A: 

As you said you get AP's handle and pass it to PP, so PP has that handle around, so when AP is closed PP can check if that window handle exists using windows API IsWindow or IsWindowVisible depending on you needs

import win32gui
win32gui.IsWindow(handle)
win32gui.IsWindowVisible(handle)
Anurag Uniyal
With this method I was able to detect whether the window was open without directly asking the AP. I still have to actually kill the app, but I think that will be the easy part. Thanks!
Fry
Why you need to kill app? which app PP?
Anurag Uniyal