LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does anyone know how to detect external application window close?

I can detect VI's panel close but not the ones from other programs. In this case, I know the title of the window and need to detect this event to trigger other actions. I tried to use event structure by registering dynamic events, but with no success. I would appreciate it if someone can help me or tell me where I can find related articles.
0 Kudos
Message 1 of 6
(4,194 Views)
It has been a long time since I have done this sort of thing, but you can do it by using the call library node to call Windows API functions using system DLLs.  Expect to spend some time figuring out exactly what to call, but the final code should be pretty simple.  This tutorial (Example 3: Call the Win32 API) should get started.  Post again if you need more help.
Message 2 of 6
(4,171 Views)
I kind of understand what you mean. I thought there might be some VIs to do exactly this thing. I guess it's not that simple.
 
Anyway, assuming I can find out the status of the window (whether it's open or closed) with a VI, what would be the next steps? I was trying to use a dynamic user event to capture the changes in window status. But I was not 100% sure because I have not used user event structures much. The LV help does not have much on dynamic user event structure. Do you know if there are any good documentation or examples online about using dynamic user events? Thank you.
0 Kudos
Message 3 of 6
(4,157 Views)
You will need to poll the window status to determine when it closes.  Make sure you put a delay in the poll loop to avoid eating all your processor time.  If this is a UI based application, a 50ms delay will be good.  I have attached a single-VI example of how you can use dynamic events to tell your program to do something else.  To use dynamic events, you have to do two things - create an event and register an event.  These two things happen in the first two nodes on the left of the diagram.  To use a registered event, you need right-click on the border of the event structure and make sure that Show Dynamic Event Terminals is checked.  Then wire your registered events into the terminal.  Note that you can register more than one event.  Note also that the data for the event can be anything you want (it is a boolean in this example).  To fire the event, use the Generate User Event VI.  The input data will be the type you specified when you create the event.  Make sure you clean up your event and registration before you exit.



Your code will probably have the top loop in the example in a different VI (the one checking for whether a window is open or not).  You may not want to generate an event every iteration of the poll, only when the value changes.

Message Edited by DFGray on 01-30-2007 08:23 AM

Download All
Message 4 of 6
(4,135 Views)

You can capture an external application window closing event, without polling, by using Windows API.

G Toolbox ($$) External Application lib can do it.  There is a demo of External App lib in LV7.1 at:

http://www.geocities.com/gzou999/demo.htm

 

George Zou
Message 5 of 6
(4,126 Views)
Thank you, DFGray and zou.
I've got the idea. Great help!!Smiley Very Happy
0 Kudos
Message 6 of 6
(4,099 Views)