System tray icon does not always show when starting app when Windows starts

P

Patrick Dugan

I am using VS2005 (vb) and I have a program that starts when Windows boots
up. Occasionally the icon that should appear in the system tray does not
show up. The program is still running in memory but the tray icon is not
there. If I start the program after Windows has booted up the icon shows
every time. I am assuming that the reason is due to the icon being created
before the system tray is loaded/running. I have used a timer with "dim
notifyicon1 as new notifyicon" every few seconds and that works but I am
afraid I am eating up memory doing that or is that "ok" to do?

Is there any way to detect if the system tray is not running so I can delay
the creation of the tray icon until it is?
 
N

Newbie Coder

Patrick,

You can handle this many ways, but here are a couple:

1) Check to see if the process is already running
2) Embed the icon in the executable

By continuing to create a new NotifyIcon object you are indeed using memory

How are you starting this application?

Hopefully you are using a module with sub main, creating an instance of your
form & running it from there. If not, you should because then you can hide
the form, display the tray icon like you want. I have a few VB.NET
applications running on startup like you wish without problems doing it the
sub main way
 
P

Patrick Dugan

The icon is embedded in the main program and it is called from an instance
in sub main. The problem is *sometimes* the icon will not show up if the
program is set to start when Windows boots up. The problem is rare but
nonetheless still happens on occassion. The question is how do I determine
that the system tray has started so I can wait to initialize the icon at
that point. I already know to look for a process but so far I cannot tell
what process indicates the system tray is up and running.

I also need to determine if Explorer crashes and the tray icons need to be
refreshed. How can you tell that has happened and you need to re-establish
the tray icon?
 
G

G Himangi

When the taskbar is recreated, the system sends the registered window
message "TaskbarCreated" whose value you can get using
RegisterWindowMessage("TaskbarCreated");

You will need to catch this message and reinsert the tray icon

If you dont mind a commercial solution, you can try our ShellNotifyIcon
component at http://www.ssware.com/shlobj/shlobj.htm

---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : GUI Controls For Drop-In Windows Explorer like Shell
Browsing Functionality For Your App (.Net & ActiveX Editions).
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions,explorer bars and BHOs
rapidly in .Net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top