Results 1 to 5 of 5

Thread: [RESOLVED] Repainting tray icon after Explorer crash

  1. #1

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Resolved [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!

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Repainting tray icon after Explorer crash

    Can you clarify this method a little further, please?

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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

  5. #5

    Thread Starter
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Repainting tray icon after Explorer crash

    Okey. Don't like hooking to much, but, it works

    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width