LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to select focus for specific front panel

Hi Guys

 

I have an application that needs to launch another LV build .exe file. For doing this I call the system exec.vi.. This is working fine. 

However - when calling the system exec VI the focus of my program window is removed and never returns. So for the user to add input to the program he just started he needs first to click the window to regain focus.. Is there a clever way of forcing the focus back on the initial program window?

I tried with the key focus parameters, but this seems to only have effect inside the specific window, and irregardless of it has the over all focus or not. 

I'm pretty sure that this one is a trivial problem, but I can't quite seem to crack it at this hour.. Anybody with a simple advise for this one??

 

Thanks in advance.. 

 

Jacob

LV2010 SP1, Win7

0 Kudos
Message 1 of 14
(8,911 Views)

Hi Jacob,

You can try property node>>Front panel>>Is frontmost. This will work only if frontpanel in your exe is not of floating type.

Use this property node after you call exe.

I have not tried this with combination of exe and vi, so let us know if this works for you.

Gaurav k
CLD Certified !!!!!
Do not forget to Mark solution and to give Kudo if problem is solved.
0 Kudos
Message 2 of 14
(8,892 Views)

Hi Gaurav

 

Thank you for your suggestion.. the property node seems to be only valid for a single execution thread (if that is the proper word)

If I do a program that calls 3 frontpanels and make a "mother frontpanel" with bools for selecting which FP has the focus this works. 

But since in my case, the focus has moved to a completely different app instance, the FPisfrontmost property apparently has no effect.. 

I've been trying to generate a front panel activity, but this is apparently not registered by windows, and only raises a flag internally in LabVIEW.

Any other suggestions?

 

best regards

Jacob

0 Kudos
Message 3 of 14
(8,883 Views)

Hi Jacob,

I would suggest that you use the VI server reference and set it to "This Application", create a Method node and choose "Bring to front".
I have a attached some example VIs of which you can build executeables and try it out.

Is this what you needed?

Have a nice day.

Download All
0 Kudos
Message 4 of 14
(8,865 Views)

Hi Kristoffer

 

Thank you for your input.. The Bring to front method seems to only work within the same application instance, and since I'm calling an external LV .exe file this is not really working.. Come to think of it, having this option at all would probably result in numerous programs constantly trying to be the frontmost and the one with the focus, and I'm not sure that is really how the user wants his / hers computer to behave.. 

 

So maybe let me rephrase the task at hand.. Is it possible to perform a call to system exec launching a program with out handing over the focus to the new program - somekind of "launch silently" function - might be a parameter to pass directly to the cmd.exe but I haven't been able to locate it, so any help is appreciated.

 

b.r.

 

Jacob

0 Kudos
Message 5 of 14
(8,840 Views)

update:

 

Okay - so it turns out that the "bring to front" does actually work, but only inside the development environment. Initial code did not wait for the program to actually launch, and since system exec return immediately, the bring to front call was wasted.. 

I've gathered everything in a project to make the problem more easy to work on.. 

 

In short:

"front panel" vi is the main app - it launches the "service app" and then call the "bring to front" method. 

"bring to front" is the "service app" it does nothing but simulate somekind of activity that a service would do.. (in my real world this would be the sample engine for an OEM DAQ)

 

When running the "front panel" vi from the dev system, it works just as expected - it launches the service exe file (provided that you have build the exe first!) then regains the focus when bring to front is called. 

When building the "front panel" as an exe and running it this functionallity stops.. why?

 

I'm sure there is a clever "this is how LabVIEW works on the lower levels" explanation to this, but I'm not smart enough to figure what it is.. Are you?

 

Attached is the entire project including build specs for two exe files, and the VI's.. Exe files are not included to avoid problems with various virus filters. 

 

0 Kudos
Message 6 of 14
(8,835 Views)

Hi Jacob,

If you use the VI properties and set the top level VI as minimized under windows run time position for the service application, this should do the trick.

Are you able to do / try that and get back to me?

0 Kudos
Message 7 of 14
(8,820 Views)

Try this.  Note: It's the last node that restores focus to the original VI, the rest of that stuff is just to figure out when to do it.

0 Kudos
Message 8 of 14
(8,807 Views)

Hi Guys

 

Sorry, nut none of the suggestions are working.. As long as I stay in the dev env and just run the "main program" as a VI, it works well - the focus returns to the main app once the service has launched.... As soon as I build it and run it as an exe file, the focus does not return. Changing the properties to minimized did not change this behaviour. I've also tried working with the FP Open method to see if it would be possible to convince the focus to return using combinations of activate and state (Hidden for instance) No such luck... 

 

PCardinale - I'm not sure what the large amount of localhost resolving does in your VI? Are you just making sure that the "service program" is launched and running, before you call the "bring to front" method, or is there a deeper meaning?

 

New information not provided earlier... 

I'm running windows 7 - caused problems before on all kinds of things, so why not here as well:-) I'm out of Xp's at the moment, so can't check the behavior on there. 

 

In the dev env - if I have the block diagram of the main app open when I run it - it is actually the block diagram, and not the front panel that regains the focus, given that it was the block diagram that had the focus when I launched the program. 

 

So question still remains - why is it that the project attached earlier works well, if the service is an .exe file and the main app is a VI running in the dev env, but as soon as the main app is build and run as an exe, the bring to front call does not provide the focus back to the app.....???

 

b.r.

Jacob

 

0 Kudos
Message 9 of 14
(8,800 Views)

The bulk of the code is setting up the 2nd app so that an application reference can be acquired; and with that it can be determined when the 2nd application is running.  Try adding a delay before "Bring To Front".

0 Kudos
Message 10 of 14
(8,783 Views)