SysTrayIcon disappear

Just starting out? Need help? Post your questions and find answers here.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: SysTrayIcon disappear

Post by spikey »

Try this, you should get a custom notification when the taskbar restarts. (You can simulate it by killing explorer and then using the run option in task manager to restart it). Its not a solution but at the very least it should help you work out if its a taskbar restart that's causing the problem. If it is, it should allow you to handle the failure more gracefully.

Code: Select all

; Change this if you're already using custom events.
#TaskbarCreated = #PB_Event_FirstCustomValue

Define.S sMessage = "TaskbarCreated"
Define.I uTaskbarRestart = RegisterWindowMessage_(@sMessage)

Procedure WinCallback(hWnd, uMsg, WParam, LParam) 
  
  Shared uTaskbarRestart
  
  If uMsg = uTaskbarRestart
    ; You need to alter the parameters to provide the right window number (the first zero, second parameter, in this line).
    PostEvent(#TaskbarCreated, 0, 0) 
  EndIf
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
  
EndProcedure 

If OpenWindow(0, 0, 0, 200, 100, "Callback", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget) 
  
  SetWindowCallback(@WinCallback())    ; activate the callback
  
  Repeat 
    Select WaitWindowEvent() 
      Case #TaskbarCreated
        ; The task bar has been (re)created.  Free the existing icons and create new ones here.
        ; Log a fault or whatever...
        Debug "#TaskbarCreated"
        
      Case #PB_Event_CloseWindow 
        End 
    EndSelect 
  ForEver 
  
EndIf 
Balmung
User
User
Posts: 24
Joined: Sat Dec 22, 2018 9:15 pm

Re: SysTrayIcon disappear

Post by Balmung »

Thanks, interesting code and it works here.

So there is no direct way to detect if the Icon is destroyed?
BarryG wrote:IsSysTrayIcon() will only tell you if your icons were created or removed by your app, and NOT if they were destroyed by an external factor like a desktop reset.

Take this amended example from the manual, and run it. While it's running, kill "explorer.exe" and restart it, and then click the ButtonGadget() from the code. The debug output will show non-zero for both, falsely indicating that the systray icons are valid, when in reality they're clearly dead and gone. This is because the code never used RemoveSysTrayIcon() on them.

In other words, it's totally pointless to check IsSysTrayIcon() if your app never uses RemoveSysTrayIcon().
Thanks, but:
Balmung wrote:Ok, i see, i was wrong. If you kill explorer.exe and start it new than my tools icon came not back. So issystrayicon() did not work on that. Is there a other way to test it? Because from all other software the icons are back.
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: SysTrayIcon disappear

Post by BarryG »

Balmung wrote:Is there a other way to test it? Because from all other software the icons are back.
You do it the way Spikey showed above. It's similar to how I do it for my apps.
Post Reply