I am using Aaron Young sample to add My Appl to a systray and it is very good - BUT - i would like to change the icon in some event in my project. How Can i accomplish that???



Aron Young Sample:


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

Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long

Private Const NIF_ICON = &H2
Private Const NIF_MESSAGE = &H1
Private Const NIF_TIP = &H4
Private Const NIM_ADD = &H0
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const WM_RBUTTONUP = &H205
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202

Private tTrayIcon As NOTIFYICONDATA

Private Sub Form_Load()
Picture1.Visible = False
'Create a System Tray Icon
With tTrayIcon
'Set the Handle to the Icon you want to Display
'This could be any Icon, for this example I'm using
'The Icon assigned to the "Icon" Property of the Form.
.hIcon = Icon
'Tray Icon Messages are ReRouted to a Window Handle of
'Your choice, typically it's wise to use a Picturebox
'For this purpose.
.hwnd = Picture1.hwnd
'Set the "ToolTip" Caption that will Appear
.szTip = Caption & Chr(0)
'Set the Message used when Redirecting to the Specified
'Window Handle
.uCallbackMessage = WM_MOUSEMOVE
'Set the Flags to add an Icon, ToolTip and Callback Message
.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
'Give the Icon a Unique ID, (This is unique to this Thread/App)
.uID = 1
'Set the Size of this Structure
.cbSize = Len(tTrayIcon)
End With
'Add the Icon to the System Tray
Shell_NotifyIcon NIM_ADD, tTrayIcon
End Sub

Private Sub Form_Resize()
'Don't show the Form in the Taskbar when Minimized
If WindowState = vbMinimized Then
Hide
WindowState = vbNormal
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
'Remove the System Tray Icon when the Form Unloads
Shell_NotifyIcon NIM_DELETE, tTrayIcon
End Sub

Private Sub mnuExit_Click()
'Unload the Form from the "Exit" PopupMenu Option
Unload Me
End Sub

Private Sub mnuShow_Click()
'Show the Form from the "Show" PopupMenu Option
Show
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'This is the Event that's passed the Callback Message Data
'From the SystemTray Icon
Select Case ScaleX(X, vbTwips, vbPixels)
Case WM_LBUTTONDBLCLK
'Double Click on SysTray Icon to Show Form
Show
Case WM_RBUTTONUP
'Used for Displaying a Popup Menu
Me.PopupMenu mnuPopup
End Select
End Sub



Best Regards