LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Activating a window programmatically in Win2000.

Writing an application in LabVIEW 7.0 that must run under XP, NT, and Win2000. Multiple application windows are open at the same time, and the operator would find it useful to move to a specific application window (make it the front-most window and activate it (so it has keyboard focus)) by using a dedicated function key (e.g., F2=App A, F3=App B, etc.). My code captures the function keypress event is the main event loop of each application (executable) (this is necessary because we don't know which application has keyboard focus at the moment). The value of the function key is translated into a message to the application that is desired to bring front-most and activated. A message is sent over a TCP/IP connection to that application so it can make itself the front-most window, and activate its front panel. 
 
I have tried various methods for doing this. There is a WinUtil.llb library that NI supplies, that contains a VI called "Move Window To Top.vi". It has a Boolean flag input that allow you to choose to activate the window or not. I've also tried to use the VI property node, with the properties (front panel window -> IsFrontmost set to TRUE, and the property front panel window -> state set to STANDARD.
 
If I run as from a VI, I can get my code to work under XP, NT, and Win2000. When I compile my code, it works well under XP and NT. Under Win2000, the front panel specified is brought forward, but not activated. So, it doesn't have keyboard focus, and an additional mouse click it needed to give the front panel the active state.
 
Does anyone know how to activate a window programmatically (in an executable) from Win2000?
 
-Steph  
0 Kudos
Message 1 of 3
(2,850 Views)
Hi Steph,

I do agree that the behavior with Windows 2000 is different that the other OSs. For some reason, it is not easy to regain focus of a VI programmatically, once it is lost. I have created a small example consisting of one VI that calls itself to be minimized and restored continuously. In addition to that, the property "Front Panel Window » Is Frontmost" is set to true and the "Move Window to Top.vi" from WINUTIL.llb is called - all for the reason to regain focus of the VI. The issue is that this functionality will not work on a Windows 2000 machine.

I have reported this issue to R&D so they are aware of the Windows 2000 behavior. In case you want to try the VI mentioned above, I have attached it to this email.

Thanks for reporting the issue!

Message Edited by Philip C. on 07-28-2005 03:29 AM

- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 2 of 3
(2,830 Views)
Hi Steph,

After discussing this issue with the LabVIEW developers, it turns out that the issue is pure Windows 2000. LabVIEW simply calls the Windows API through the "WINUTIL.llb", so it's not a LabVIEW limitation that it doesn't work in Windows 2000. After some further investigation, it turns out that in Windows 2000, only a window with focus can give focus to another window. This is causing the VI not to be able to give itself the focus when executing. Probably there is a way to do it correctly in Windows 2000, but that is a question for Microsoft.
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 3 of 3
(2,812 Views)