Click to See Complete Forum and Search --> : Icons in systray problem


Mark Berkowicz
March 26th, 1999, 03:49 PM
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

Chris Eastwood
March 26th, 1999, 04:35 PM
Hi Mark


How did you setup the icon with NOTIFIYICONDATA ?


This is the code I used in the VBCodeLibrary Example on the CodeGuru site :


Private Sub SetupSysTrayIcon()

'

' Setup the System Tray Icon

'

Dim tTrayStuff As NOTIFYICONDATA



With tTrayStuff

.cbSize = Len(tTrayStuff)

.hwnd = picSysBar.hwnd

.uId = 1& ' uid is a unique identifier for the systray icon

.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE

.uCallBackMessage = WM_MOUSEMOVE

.hIcon = Me.Icon

.szTip = "VBCodeLibrary Tool" & vbNullChar

Shell_NotifyIcon NIM_ADD, tTrayStuff

End With



End Sub


Private Sub KillSysTrayIcon()

Dim t As NOTIFYICONDATA

'

' Kill the icon in the system tray

'

With t

.cbSize = Len(t)

.hwnd = picSysBar.hwnd

.uId = 1&

End With



Shell_NotifyIcon NIM_DELETE, t


End Sub


I call the SetupSysTrayIcon on Form_Load and the KillSysTrayIcon on Form_Unload.


Are you setting the '.uid' parameter to be the correct icon identifier ? I imagine this could be your problem.


By the way I'm just finishing a new project for the CodeGuru site that adds a shortcut to your favourite programs into the systray (using the correct icon) and can start an instance of that program with one click - it uses all the NOTIFYICONDATA structure throughout with subclassing to react to the clicked icon (interested ?)


Regards


Chris Eastwood


CodeGuru - the website for developers

http://www.codeguru.com/vb