I'm having trouble removing icons from the systray when my apps main form closes. The icon remains in the tray until I pass the mouse over it. I guess I'm deleting it properly but the systray is not refreshing. I'm using the Form_Terminate sub to remove the icon calling the following function:


Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean


Private Sub Form_Terminate()

'Delete the added icon from the taskbar status area when the

'program ends.

Shell_NotifyIcon NIM_DELETE, nid

End Sub


I declare:

Dim nid As NOTIFYICONDATA


'This is my type declaration:

'It declares the variable to pass to the Shell_NotifyIcon

'function.

Private Type NOTIFYICONDATA

cbSize As Long

hWnd As Long

uId As Long

uFlags As Long

uCallBackMessage As Long

hIcon As Long

szTip As String * 64

End Type


Any clues how to refresh the tray after I remove the icon?

Thanks,

Mark