LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect frontmost VI

Hello All;
 
I am adding some additional features to an image analysis tool, which requires me to have multiple VIs open at once.  Each of these VIs communicate with a central server to exchange data and so forth.  This application requries several of these VIs to be open simultaneously; however, I only want the active VI (i.e. frontmost) VI to perform data transfer at any given time (to reduce number of queues used, and so forth).  I do not want to use any kind of a polling structure to inform the server which VI is currently active (i.e. poll the VI property for Frontmost); rather, every time I switch active VIs, I would prefer it to send a queue or notifier or something to the effect of "Hi!  I'm active Now!" or something to that effect.
 
I have been playing around with the event structures, and the closest I have come to achieving this is to use the "Mouse Down?" event to trigger a queue to the main VI.  However, this would potentially mean that every time I click on the VI, that it would send the same queue.  This is also not exactly what I want.  Is there an easy way to achieve this?
 
I will attach a sample main and daughter VI to illustrate where I am currently.  I am using LabVIEW 8.0.1.  Any insight would be appreciated.  Thanks!
 
DJH
Download All
0 Kudos
Message 1 of 9
(3,944 Views)
You might look for a .NET assembly or Win32 API function that gives the currently active window. A .NET assembly would probably be your best bet, since you could register for an event if one existed to detect changes in the active window, rather than polling.
Jarrod S.
National Instruments
0 Kudos
Message 2 of 9
(3,931 Views)
Have you tried properties node=>front panel=>Is Front most ?
See attached VI.
 
George Zou
 
George Zou
0 Kudos
Message 3 of 9
(3,920 Views)
In his post he mentioned he didn't want to poll that property.

But a perfectly valid solution would be to add in one extra layer of communication on top of the Mouse Down event. Have the daughter VIs share a notifier. When a particular daughter VI gets focus (using the Mouse Down property), it sends a notifier to the other daughters telling them about the focus change. It then sets an internal flag (shift register) that ignores all further Mouse Down events. In other words, the Mouse Down event case has a True/False case structure inside of it.

If another VI sends notification to a daughter VI that it has focus, the daughter Vi that receives the notification flips the flag back on to listen for Mouse Down events.

This is all completely event-based with no polling, and it doesn't send any extraneous messages to the main VI about which daughter has focus.

Any thoughts?
Jarrod S.
National Instruments
Message 4 of 9
(3,916 Views)
For example... Open Mother.vi (top-level) and press run. Hovering the mouse over one of the daughter VIs gives it universal focus, as does clicking anywhere on the panel. The daughter VIs only listen for this focus if they don't currently have it. The mother (server) always knows who has current focus, so the communication can proceed accordingly.
Jarrod S.
National Instruments
0 Kudos
Message 5 of 9
(3,915 Views)
Thanks Jarrod S.;
 
You are quite right; polling is not an option I want to pursue.  I think your solution pretty much answers my question, or at least puts me on the right track, and with some modification, I should be able to make use of it in my application.  When I get it working properly (or if for whatever reason it doesn't), I'll add to this post to let everyone know.
 
Thanks again!
DJH
0 Kudos
Message 6 of 9
(3,900 Views)
In the interest of cleaning up open threads...
 
Jarrod S's solution did provide me with an entirely event-driven means, however, in the end I went with the polling property.  I already had a timeout condition wired in my event structure, so I was not actually adding a separate polling routine.  I put in some extra logic so that the VI could figure out (per each timeout condition) if the frontmost condition had changed.  If it had (i.e. went from background to frontmost), it performed a particular function; if it did not (i.e. went from frontmost to background, or just stayed in background), no function was executed.
 
One of the problems with the event driven structure, is that it would work well enough when using the mouse to select stuff, but when using the Alt-Tab switching function, it was rather useless.  Although there probably is a way to program this in as well, it seemed much easier to use the timeout and poll the Frontmost? property.
 
Hopefully, this will help anyone else who has the same requirements.
 
DJH
0 Kudos
Message 7 of 9
(3,855 Views)
Hi Hannamon,

I have not read the whole thread, but there is an VI activation event. Search on  Lava for this event and you will figure it out!

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 8 of 9
(3,841 Views)

Hello All;

I am installing LabVIEW 8.2, and so having some time to kill, I am revisiting my old posts to close some items.  As such, I have a bit of a warning regarding the use of polling the "VI is Frontmost" property.  I have just closed out another thread in which I experienced a Win2K crash in my runtime application, when WinXP ran fine.  After many hours of debugging, I found that the reason for my crash was because of my "VI is Frontmost" polling routine.  As part of my application, I also used subpanels and tab controls, and cannot say for certain that the use of these are unrelated (I forwarded everything off to NI, and they have notified R&D of the potential issue).

I am attaching a ZIP file, containing an example (i.e. not actual code) of the type of polling structure I had in place.  It seems when dynamically loading VIs instead of putting them all into subpanels within tab controls is perfectly fine.  However, there may be problems when trying to utilise all of these aspects at once.

Just to be clear, I am not looking for an immediate solution to this, as I have rewritten that section of my program to no longer require this functionality.  Just thought I'd pass along the information.  Hope it is useful to someone.  Also, if anyone HAPPENS to know why this is, or has run into this before, let me know!

DJH

0 Kudos
Message 9 of 9
(3,784 Views)