Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TrayIcon after explorer crash

 
Krystian Gor
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
did you get an answer?
I have the same problem :-(
 
Krystian Gor
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.
 
Sharon Beck Lavie
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49382
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Do you have answer on the issue?
I still have this problem without any solution.
 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic