From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Focus between two applications

Solved!
Go to solution

Hello,

I am working with two applications simultaneously, one of which is made with CVI and one not (e.i. explorer). The application made with CVI every 20 seconds displays a new panel and take the focus (accordingly the other app lose the focus), but I would always keep the focus on the second application (Explorer). Is it possible?

 

Thanks a lot

Daniele

 

0 Kudos
Message 1 of 4
(3,579 Views)
Solution
Accepted by topic author d.ghisla

Danielle:

 

Matteo gave you some helpful links if you want to give your app focus.  But when I read your post, it sounds like your app is taking focus and you don't want it to.

 

The attached sample project shows two different ways of allowing another app to keep focus when your app would normally take it.

 

Both methods use the Windows SDK (a.k.a. Win32 API) functions to get and/or set the foreground window (the one with focus).  The Windows SDK is not installed by default with CVI.  It comes with the Full package and the NI Developers Suite, but not with the Base package.  If you have the full package or suite, and you don't have the SDK installed, you just need to run the CVI install again, and select only the SDK (or Win32 API).

 

The basic idea behind the first method is that before you display your new panel, you check to see which window is in the foreground using GetForegroundWindow(), then display your new panel, and then set the previous app's window to the foreground again using SetForegroundWindow().  The drawback to this method is that your new panel has one quick blink of focus before focus is returned to the other app.

 

The second method checks if your CVI app is the foreground window before it displays the new window.  It does not display your new panel if some other app has the focus.  This way you don't get any blinks of focus to your CVI app.  Depending on the purpose of your new panel, you may need to display the new panel if and when your app receives the focus instead of waiting for up to 20 seconds to display it.

 

For demo purposes, this sample app just redisplays the main panel instead of displaying a new panel.  Both methods will work the same way for a new panel as well.

 

The instructions for running the demo and seeing the two different methods are on the main panel.  Just build the app and run it.  I tested this sample in CVI 6.0 and 9.0.1.

 

After saying all that, I still have a question for you.   Why does your CVI app display a new panel every 20 seconds?  You can update an existing panel without using the DisplayPanel command and forcing focus back to your CVI app.  Do you need to display a new panel?  And what happens after 20 seconds?  Does the first new panel get hidden or destroyed?  Does another new panel get displayed?

 

There might be something even easier you can do without any of this SDK stuff, like not using DisplayPanel if all you need is SetCtrlVal.  (But writing this sample made for a fun exercise).

Message Edited by Al S on 11-04-2009 07:06 PM
Message 3 of 4
(3,539 Views)

Thanks AI_S

You solved my problem. I did not know about the SetForegroundWindow () function.

 

 

Ciao

0 Kudos
Message 4 of 4
(1,253 Views)