To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This is a LabVIEW API for creating an icon in the Windows system tray (AKA notification area), complete with nested menus and events. It uses the .NET framework NotifyIcon class. While developing this, I found this similar implementation, but continued with my own to implement a few more features I required.
Description
If you are looking around for a way to have a system tray icon for your LabVIEW application, as I was, you'll find that .NET is the way to go. You can try calling the Win32 API via Shell32.dll function Shell_NotifyIcon, but that is often difficult to do from LabVIEW directly. You will also have a very hard time getting events, such as mouse clicks on the icon or menus, back to LabVIEW. Another option is existing ActiveX wrappers people have made. NI has one that comes with CVI (posted here), and there are others around the web that are sometimes free but sometimes not (random example, random example, VI wrapped example). ActiveX gives a nice API and solves the event issue, but you are limited to the features that have been exposed to you through that particular ActiveX wrapper, which is up to the wrapper developer. However, .NET acting as the new Windows API gives a nice, featured interface that is easy to use from LabVIEW.
Features:
VIs are saved in LabVIEW 2009, and this was developed with .NET 3.5. I you have a different .NET version/requirement just give it a try. I would be surprised if this wasn't pretty backward/forward compatible.
Installation instructions: Download NotifyIcon.zip, then unzip to your user.lib folder and restart LabVIEW.
BUG FIX 4/5/2011 - Some LabVIEW references to objects were not being properly closed, though the objects themselves were being destroyed. This could cause a memory leak which would be noticable if you do a lot of icon or menu changing. NotifyIcon.zip has been updated to fix this. Thanks to DSmith for finding the issue. See the comment from DSmith below for more information.
Steps to Implement or Execute Code
Run either of the two examples included in the attachment for guidance on using this API.
Requirements
Software
LabVIEW 2009 or later
Hardware
None
**This document has been updated to meet the current required format for the NI Code Exchange. For more details visit this discussion thread**
Description-Separate-2Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Very nicely done! And thanks for the helpful links to existing documents like the CVI implementation as well.
i need this show notify vi's in labview 8.6 can you help me...?
Unfortunately, because native recursion is a feature of LabVIEW 2009, this code can't be directly ported to 8.6. I would recommend using this similar implementation, or at least using it as an example of how to use the .NET interface to NotifyIcon from LabVIEW.
This is fantastic! Very in-depth and helpful, handy links too.
This Is very nice and useful
thanks a lot
<p>Thanks for your vi's! I had only one question: how to put the running application completely to the notification are, like a virus killer or something similar? here (http://digital.ni.com/public.nsf/allkb/E277CBA8C9065C1A86256D250021D9FA) the title is right, but it seems to me that this method adds the icon to the notification area with many functionality, but leaves the running application in the system tray like a normal application e.g. word processor. thank you!</p>
To remove the item in the Task Bar, go to File >> VI Properties >> Window Appearance >> Customize... and uncheck "Allow user to minimize window." That works for VIs. For an executable, I think you also need to add the ini key HideRootWindow=True.
Hi all,
(beside HideRootWindow=True there is an another useful possibility in the ini-file to allow multiple instances of the app: allowmultipleinstances = TRUE.)
To this topic: I have only one problem. In the example there is a basic solution to show the balloon tooltip, namely just set a boolean to true. But how could I catch the event that the user is standing with the mouse cursor over the icon of my application in the notification area? There are many possibilities in the Notifiicon User Event: User event structure, but they doesn't seem to work at this level. This would be the final step to the perfection
thaks a lot. zsolt
Zsolt - This is available from the MouseMove event, which is handled as a LabVIEW User Event with this API in the same manner as the rest of the events. However, it's tricky to use because as you move your mouse over the icon you will receive a series of events. There isn't a simple single event (like LabVIEW's "Mouse Enter" event) available from the NotifyIcon .NET class.
If all you want is the pop-up ToolTip text that usually shows when you put your mouse over an icon in the system tray, just write to the Text property of your NotifyIcon instance.
Hi Brinoceros,
thanks for the quick reply. Could you please explain your last tip a little more detailed, maybe just with a screenshot? I can't find the right solution. thank you.
Try this:
If that's not what you're after, take a look at "NotifyIcon - Example 2.vi" and add MouseMove to the event registration.
Fabulous
Hey all,
First, let me say that this is great. I've been using this to update some of our internal tools to take up less screen space, and it has been great so far. However, in my use of the program, I discovered a bug. The set icon VI does not properly clear out the reference to the old icon, resulting in a slow memory leak. I created a set of VIs and exes which demonstrate the problem, below.
http://decibel.ni.com/content/docs/DOC-15493
(warning: I set the loop on the demonstrator VI to run as quickly as possible, so the buggy application.exe will go from 0 to about 300 MB of ram used in ~4 seconds. Be very very careful that you do not crash your machine)
The files attached to that link also contain the fix for that bug.
Thanks again for the great example!
Thanks DSmith. It is now fixed, along with a couple of other instances of the same issue. NotifyIcon.zip has been updated with the changes.
Hmm...I can't get LV to catch the "Disposed" MenuItem event. Has anyone else had this problem? Does anyone have any debugging tips to see whether the event is firing correctly, or whether LV is listening to it properly?
The reason you cannot catch the Disposed event is that in "NotifyIcon - Destroy.vi" all events are destroyed before the Dispose method is called. I'll change this when I get the chance, but in the mean time you can switch the order of execution of the Dispose method and where the event registration is destroyed in "NotifyIcon - Destroy.vi" (just switch their location along the reference wire).
Hello Brinoceros,
Your code works great with XP but having problems with Windows 7.
Any suggestions?
It works fine in Win7x86 for me. Which bitness are you using? Can you describe the "problems" in more detail? Do you have .NET 2.0 or higher installed on your Win7 machine?
Hi
I have used this notification, It works with the source code nicely.
But when I create EXE / Installer and tried to install on other System, then it wont work properly.
Kindly suggest me on this
Regards
Prabhakant
Hi David S,
I am using Windows 7 X86 - 32BIT and the .NET 2.0 is installed. Also, I have tried a Windows 7 X86 64BIT with .NET 2.0 and still the same problem.
What I see is that the program loads but never is allowed to have the ICON in the Tray before the program aborts.
I am planning to install LabView on to Windows 7 32Bit computer and then run the code through the LabView environment Window.
Any other suggestions?
Thanks,
Mike
Hi All,
Can we move support-type questions to the discussion forums? I'll try to help out as I can, but the comments on this document aren't really the place for it and you'll get much better support on the forums. Feel free to drop a link to your forum post as a comment on here to draw some attention, but lets keep the full support discussions on the forums. Thanks!
For you guys having trouble with executables, I have used this code in executables on XP and Win 7 x86 so it should work fine. It should really just depend on the .NET API anyway. Make sure you're properly handling errors from the VIs so you'll get feedback from your executable. And just simplify things: try building one of the supplied examples into an executable and see if that works.
I need it in 8.5 version. Can anybody convert Notifyicon.zip to 8.5 and send to me.
Sorry, it can't be done. See my first comment on this document (3rd comment overall).
This is really helpful. THank you! It works great. Any issues when creating an application? And I am assuming all the issues concerning memory leaks have been fixed and this pallete can be safely used now.
Seems to work well even in LV8.5, it just takes changing the vi to fit the old style of recursion; a very minor addition of code.
HideRootWindow=True doesn't seem to work for executables in Windows 7. Am I doing something wrong? Is there another way to do this? I want to hide the application window taskbar icon for an executable.
Thx for the greate code and help file
Hi, I had some problem with memory leaks when changing the menu items and re-registering the events. I've posted it on the discussion forums here: http://forums.ni.com/t5/LabVIEW/NotifyIcon-Memory-Leak-amp-New-Function/td-p/2702093. As part of implementing a workaround, I also implemented a new function which enables/disables menu items - it is attached to the post.
ignore, deleted my post
Frist I have to say, Great Work!
I have two questions for customization of the tray icon menu:
Can I customize the checked/radiocheck Icons?
Why it is not possible to check a partent menu-item?
Thanks Jakob
Just got this working, great work! This should be included in LabView out of the box. I am excited to see how I can utilize this in my applications.
I recommend adding the GC.Collect() -workaround to unreserve the callback VI and it's children.
See: https://www.ni.com/en/support/documentation/bugs/14/labview-2014-and-2014-sp1-known-issues.html#4681... and https://forums.ni.com/t5/LabVIEW/net-event-callback-VIs-Why-do-they-never-leave-running-state/td-p/3...
For my application it was enough to call it in the Destroy VI in the end.
This seems to work fine, but:
- It doesn't display an info box (not sure what the official name is) when the mouse hovers over the tray icon, as in e.g. when I hover over the sound tray icon it displays a little box with "Speakers: xx%"
- Is this because this NotifyIcon implementation uses "ContextMenu" instead of its replacement "ContextMenuStrip"?
-If so, has anyone updated it with the new functionality of "ContextMenuStrip"?
@Brinoceros
Answering my question (should have spent a little more time looking at it).
This implementation never sets the NotifyIcon text property. Seems it could be added as an argument to "NotifyIcon - Create.vi" quite easily.
Hi.
Would you consider making a VI Package of this tool? It would make the installation much better and more safe.
Thanks.
I made some modifications and update in this library (thanks for it, it is a good stuff).
How can I upload here if I would like to share?
Just found that there is an "Averna Notify Icon" package published in VIPM.