aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes TrayIcon after explorer crash Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "TrayIcon after explorer crash" Watch "TrayIcon after explorer crash" New topic
Author

TrayIcon after explorer crash

Krystian Gor
Ranch Hand

Joined: Jan 11, 2011
Posts: 30
I think each of us witnessed Windows explorer crash. Taskbar disappears but it reloads after this. Unfortunatelly not all tray icons appear reloading. It depends on the software using tray icon.

I've been playing with tray icons and it works well great until explorer crash happened. My appplication runs in the background but I'm not able to show its window beacause tray icon is gone. The only thing I can do it to kill it by task manager without saving progress.
I'm using Windows XP and tried to simulate this crash by killing explorer.exe process through task manager CTRL+ALT+DEL and reloading it by File --> New Task --> "explorer" --> OK
After this I'm not able to add icon again because it says this icon is still there. Indeed it is because I'm able to get this icon though I can't see it.


when adding icon it throws java.lang.IllegalArgumentException: adding TrayIcon that is already added
Of course I can solve this problem by removing icon and adding it again:

Any ideas how can protect my application and how can I detect that my icon disappeared after explorer crash?
It would be stupid to schedule tray.remove(...) and tray.add(...) just to show possible "hidden" icons.
Sharon Beck Lavie
Greenhorn

Joined: Sep 26, 2011
Posts: 3
Hi,
did you get an answer?
I have the same problem :-(
Krystian Gor
Ranch Hand

Joined: Jan 11, 2011
Posts: 30
No.
Sharon Beck Lavie
Greenhorn

Joined: Sep 26, 2011
Posts: 3
I saw this link:
http://syedgakbar.wordpress.com/2008/07/14/restore-notification-area-icon-after-explorer-crash/

I don't know how to register windows message to java.
Do you?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Sharon Beck Lavie wrote: . . .

I don't know how to register windows message to java.
Do you?
No, and I think this question too difficult for "beginnning", so I shall move it.
Sharon Beck Lavie
Greenhorn

Joined: Sep 26, 2011
Posts: 3
Hi,
Do you have answer on the issue?
I still have this problem without any solution.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3433
    
  47

If I understand the blog correctly, there is a message sent by Windows (the OS) to all existing windows whenever the Explorer starts and creates a new taskbar. To receive these messages, you need a window handle. Though the JVM undoubtedly creates some windows to integrate running application into the OS, you probably won't be able to get handles of these windows, nor process the messages OS sends to them.

Assuming there is no native way to handle this from Java (which I honestly don't know), a possible way would be to program a DLL and use it to create a hidden window at application startup. This window would process the WM_TASKBARCREATED message. Even though a callback from DLL to Java is probably possible, I personally would just set a flag in the DLL upon receiving this message and use a timer to poll this flag time from time (say, once per second). If the Explorer just crashed, waiting a second for the icon to get resurrected is not a bad deal. Also, before the application exits, the DLL's window should be destroyed. Some thoughts should be also given to the possibility of multiple clients of the DLL (one DLL window could serve multiple JVMs), but we're getting quite stretched already.

It's a looooong time since I was doing DLLs and Windows development in C, so I can't go into greater detail here, but in my opinion this should be viable. However, you do need some experience with DLLs and JNA/JNI in Java.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TrayIcon after explorer crash
 
Similar Threads
How to Add a Systemtray Icon on several machines ?
Error loading image jar
reduce display frame SystemTray
tray icon is not displaying
my frame starts up minimized...