Example Code

Programmatically Move Any Window to the Front

Code and Documents

Attachment

Overview

This VI will programmatically move a window to the front whether its a LabVIEW window or not.

 

 

Description

This VI will programmatically move a window to the front whether its a LabVIEW window or not.  There are two Windows APIs that are used to achieve this.  The first one (FindWindow) acquires the handle of the window that you want to bring to the front.The name of the window is passed into the lpWindowName terminal and NULL is passed into the lpClassName terminal.  The second windows API is SetForegroundWindow. This moves the window corresponding to the passed handle to the front.

 

 

Requirements

LabVIEW 2012 (or compatible)

 

 

Steps to Implement or Execute Code

1. Open the VI "Bring Window Forward_LV2012_NI Verified"

2. Choose the window name you want to bring to front
3. Run the VI
4. Stop Execution

 

 

Additional Information or References

 

BD.PNG

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Regards,

Sara Lewandroski
Applications Engineer | National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
michelesc
Member
Member
on

Hi,

this approach seems not to work if my VI execute a SysExec and wants to keep the external application to the background.

Root cause seems you cannot move a window from a background application (that is, after LV executes Sysexec).

 

 

Tesla1977
Member
Member
on

This does not work in Win10. When calling the function when another application is at the front the LabVIEW window simply starts flashing in the taskbar. Any tips?

mckesea7010
Member
Member
on

This approach doesn't currently work for me when incorporating into an executable. Are there are any other files I need to include in my project for this to work in an executable??

wiebe@CARYA
Knight of NI Knight of NI
Knight of NI
on

Posted a new version here. (images and\or attachments are not allowed here?).

 

That handle needs to be a pointer sized integer.