[RESOLVED] Repainting tray icon after Explorer crash
This was probably answered before, but, there are just to many threads concerning tray icon issues to look through one by one and i can't seem to find it.
I'm creating a tray icon with Shell_NotifyIcon API. When Explorer (Explorer.exe) crashes it disappears. When it comes back to life it doesn't repaint it. What would be the best approach to solve this?
Thank you! :wave:
Re: Repainting tray icon after Explorer crash
You will want to test for a message sent to top level windows when Explorer restarts.
Code:
Private WM_IECrashNotify As Long
' ^^ add as module level variable
' at sometime before or after assigning the tray icon.
' If called multiple times, will always return the same value
WM_IECrashNotify = RegisterWindowMessage("TaskbarCreated")
' Now test for that message in a top level window's subclass procedure
Select Case uMsg
....
Case WM_IECrashNotify
' start your icon again. It was destroyed when Explorer Crashed
....
Case Else
End Select
Re: Repainting tray icon after Explorer crash
Can you clarify this method a little further, please?
Re: Repainting tray icon after Explorer crash
I just tried it like this and seems to work, when explorer is restarted the WM_IECrashNotify message was detected.
' FORM CODE
Code:
Option Explicit
Private Sub Form_Load()
Hook Me.hWnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unhook Me.hWnd
End Sub
' MODULE CODE
Code:
Option Explicit
Private Const GWL_WNDPROC = (-4)
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal HWND As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal HWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private PrevWin As Long
Private WM_IECrashNotify As Long
Public Sub Unhook(handle As Long)
If PrevWin Then
Call SetWindowLong(handle, GWL_WNDPROC, PrevWin)
PrevWin = 0
End If
End Sub
Public Sub Hook(handle As Long)
If PrevWin = 0 Then
WM_IECrashNotify = RegisterWindowMessage("TaskbarCreated")
PrevWin = SetWindowLong(handle, GWL_WNDPROC, AddressOf Win_Proc)
End If
End Sub
Private Function Win_Proc(ByVal HWND As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If Msg = WM_IECrashNotify Then
' Explorer has restarted, call/do something here...
End If
Win_Proc = CallWindowProc(PrevWin, HWND, Msg, wParam, lParam)
End Function
Re: Repainting tray icon after Explorer crash
Okey. Don't like hooking to much, but, it works :)
Thank you! :wave: