Removing ghost icon from the system tray
Posted on 2011-02-14
I have one VB6 app that shells a second VB6 app to perform FTP file uploads asynchronously. The FTP client puts an icon in the system tray. When the upload is complete, the app issues a NIM_DELETE and terminates, but its icon sometimes doesn't disappear -- instead it persists until the mouse is moved over it. It seems that this behavior only began when I added logic to issue NIM_MODIFY to update the tool tip to reflect upload progress as a percent.
I took the NIM_ADD, MODIFY and DELETE code directly from an MS article, and I've triple-checked to be sure I got it right. The article included code for a sample program, and I don't see a problem when running it, although it doesn't do anything but display an icon, allow it to be changed, allow the tool tip to be changed, and delete the icon.
In 17472429, Mark FreeSoftware suggested controlling the mouse to mouse-over the ghost icon, but only the FTP app knows when its done, and the ghost icon is only a problem after the app has terminated, therefore the app cannot do the cleanup. The first app doesn't know when the FTP app has completed -- the user may have proceeded with some totally unrelated function.
The first app could start a timer that waits until the FTP app is no longer running, but how would i know if there is actually a ghost icon, and if so, how would I get its x/y coordinates to control the mouse? What I'd really like is some API command that simply refreshes the System Tray...but apparently that doesn't exist.
Any ideas or suggestions would be greatly appreciated! I'm developing and testing on XP, but the app must run on XP through Win7.