Click to See Complete Forum and Search --> : How to dynamically change an Icon in the systray


Aaron
December 13th, 1999, 03:09 PM
Does anyone know how to dynamically change an Icon placed in the systray for a program. For example I would like to change the icon in the systray depending on if the program is enabled or disabled.... Any help would be great...

December 23rd, 1999, 08:44 AM
here is the UDT

Type NOTIFYICONDATA
LStructureSize As Long
hwnd As Long
lID As Long
lFlags As Long
lCallBackMessage As Long
hIcon As Long
sTip As String * 64
End Type

here is the API function
Declare Function Shell_NotifyIcon& Lib "shell32.dll" (ByVal lMessage&, NID As NOTIFYICONDATA)

some constants

Global Const NIM_ADD = 0&
Global Const NIM_DELETE = 2&
Global Const NIM_MODIFY = 1&
Global Const NIF_ICON = 2&
Global Const NIF_MESSAGE = 1&
Global Const NIF_TIP = 4&
Global Const WM_MOUSEMOVE = &H200
Global Const ABM_GETTASKBARPOS = &H5&

Global Const WM_LBUTTONDBLCLK = &H203
Global Const WM_LBUTTONDOWN = &H201
Global Const WM_LBUTTONUP = &H202
Global Const WM_RBUTTONDBLCLK = &H206
Global Const WM_RBUTTONDOWN = &H204
Global Const WM_RBUTTONUP = &H205
Global Const SW_SHOWNORMAL = 1
Global structNotify As NOTIFYICONDATA

code to add the icon
structNotify.lID = 0& ' increment this to create new instances(more than one icon)
structNotify.lFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
structNotify.lCallBackMessage = WM_MOUSEMOVE
structNotify.hIcon = Image6.DragIcon
structNotify.sTip = "TIP text" & Chr$(0)
ltemplong = Shell_NotifyIcon(NIM_ADD, structNotify)

code to remove the icon at shutdown
structNotify.lID = 0&
ltemplong = Shell_NotifyIcon(NIM_DELETE, structNotify)

code to change the icon
structNotify.hIcon = Image2.DragIcon
ltemplong = Shell_NotifyIcon(NIM_MODIFY, structNotify)

hopefully this is enough to get you going
I use this to keep our corps stock info dynamically updated in the tray from an internet feed. unfortunately each number had to be a separate icon