Example Code

FolloWin -a class implementation of a GUI information rectangle that follows the mouse cursor.

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Operating System

  • Windows

    Programming Language

  • LabVIEW G

Code and Documents

Third-Party Code Repository

Some users manage their code in repositories outside of ni.com. Use your best judgment when following links to third-party sites. https://github.com/yonicon/FolloWin-LV2023

Description

This is a demonstration of the FolloWin class.

The object implements a configurable window (minimized to a rectangle) that follows the mouse cursor around

It can be useful for doing custom measurements on graphs (as demonstrated in this demo), for doing your own custom version of the "tip-strips" or “popup-menus” or, alternatively, it can be used to annoy your fellow developers with a small note that follows their mouse cursor around. 

with a few modification you could make this window stick and follow other windows or be interactive.

It can also be used as a splash screen or a progress bar by just popping and sitting there in the center of your screen following nothing (how boring is that?), while updating its text and/or graphics and then disappearing.

 

mceclip0.png 

How to Use

FolloWinDemoGUI.vi is the top level VI of the demo. It contains an event loop.

 

The small window that follows the cursor is called FolloWin.vi and is part of the FolloWin Class. Its controls and execution are set entirely from the methods of the object.

FolloWin.vi basically runs a loop that updates its own Window Bounds and Transparency according to the mouse position and its controls. 

The object methods allows you to control the window,

 

1. Init.vi initializes and sets the initial values for transparency, update delay, x offset, y offset, width, height.

2. SetBox.vi to define the active area of the mouse cursor. 

3. Start.vi to launch FolloWin and show the window (as long as its transparency is not set to 100, Hidden is not set to true and your mouse cursor is inside the "box" you set.  

4. SetString.vi to change the text shown to a new value. 

5. SetDataString.vi and GetDataSting.vi to store needed information.

6. SetPicture.vi to set the background image of the window.

7. SetHidden.vi to hide/show the window.

8. Stop.vi to stop it from running. 

9. ShutDown.vi or start it again using start.vi 

Additional Information

When you set the offsets make sure to set them high enough. since in the case where the mouse cursor goes over the FolloWin window it generates a "Mouse Leave event" for the original control which may cause annoyance. with offsets settings of 30 however your mouse movement must be very erratic to actually be able to move the mouse cursor over the FolloWin window before it updates to a new position. so it should be OK. 

The trickiest part of this demo project was translating Screen/Mouse coordinates to graph axes values, to the index of the 2D data of an intensity graph or the (1D Data of an XY Graph) to the pixel value of the Plot Front Image for the purpose of drawing on the graph. all of those back and forth translations had to be correct for everything to work in this Demo. If you are interested in how it was done look into CoordToAxesXY.vi, GraphXYToFrontImagePixels.vi, GraphXYto2DArrayIndex.vi and GetPlotBndsInScreenCoord.vi (all in "Helpers" directory) and how they are used. 

For the text string shown in FolloWin I wanted to use monospace font, so I opted for "Courier New" if you have a problem with it just select a different font. 

As a sidenote, this demo also demonstrate how you can use a graph's front image to draw additional elements on the graph.

I used a global called StringFormatGlobals.vi to store the format strings to use and the corresponding sizes of the Followin window for each "mode".  

 

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