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.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

LabVIEW in focus

Hi

I need to know if LabVIEW is in focus. Not just a single window but all windows contained in an .exe or the development environment.

Using the user32.dll:GetForegroundWindow is not an option as it returns any window handle id.

 

Any god ideas

 

Thanks

 

 

Regards Kahr
Certified LabVIEW Architect
CIM A/S
0 Kudos
Message 1 of 5
(2,508 Views)

Hey there are those that would say I'm at my best when giving "god" answers, but be that as it may....

 

The user32.dll:GetForegroundWindow call returns a reference to whatever window is on top, but given that reference can't you find out the name of the process that owns it?  I found this code on stackoverflow that illustrates several calls.

 

Mike...


Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 2 of 5
(2,456 Views)
Arghhh...
Forum can't keep up with my speedtyping - missed that final o.
Some might consider You a god Mike (-;

I'll track down someone who can translate that strange textual code into wires.

Any other god ideas. Perhaps some already made that wrapper.
Regards Kahr
Certified LabVIEW Architect
CIM A/S
0 Kudos
Message 3 of 5
(2,439 Views)
Now that you mention it I seem to remember a fellow names George Zou (I think) that had a set of wrapper VIs for a bunch of window operations.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 5
(2,425 Views)

Hi Kahr.

 

I have made a small example, that also uses the user32.dll:GetForegroundWindow function. I simply record the original handle, and then compare that with the current handle.

 

Labviewfocus.PNG

 

If you have multiple windows, I believe you can extend this idea, and simple record the new window handle and then have two compares.

 

Can you use this example?

 

Best Regards

Alex E. Munkhaus
Certified LabVIEW Developer (CLD)
System Engineer
0 Kudos
Message 5 of 5
(2,376 Views)