Article ID: 149276
Article Last Modified on 7/13/2004
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
Global Const NIM_ADD = 0
Global Const NIM_MODIFY = 1
Global Const NIM_DELETE = 2
Global Const NIF_MESSAGE = 1
Global Const NIF_ICON = 2
Global Const NIF_TIP = 4
Declare Function Shell_NotifyIconA Lib "SHELL32" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer
Private Function setNOTIFYICONDATA(hWnd As Long, ID As Long, _
Flags As Long, CallbackMessage As Long, Icon As Long, _
Tip As String) As NOTIFYICONDATA
Dim nidTemp As NOTIFYICONDATA
nidTemp.cbSize = Len(nidTemp)
nidTemp.hWnd = hWnd
nidTemp.uID = ID
nidTemp.uFlags = Flags
nidTemp.uCallbackMessage = CallbackMessage
nidTemp.hIcon = Icon
nidTemp.szTip = Tip & Chr$(0)
setNOTIFYICONDATA = nidTemp
End Function
Private Sub Command1_Click()
'Add an icon. This procedure uses the icon specified in
'the Icon property of Form1. This can be modified as desired.
Dim i As Integer
Dim s As String
Dim nid As NOTIFYICONDATA
s = InputBox("Enter string:")
nid = setNOTIFYICONDATA(hWnd:=Form1.hWnd, _
ID:=vbNull, _
Flags:=NIF_MESSAGE Or NIF_ICON _
Or NIF_TIP, _
CallbackMessage:=vbNull, _
Icon:=Form1.Icon, _
Tip:=s)
i = Shell_NotifyIconA(NIM_ADD, nid)
End Sub
Private Sub Command2_Click()
'Modify an existing icon. This procedure uses the icon
'specified in the Icon property of Form1. This can be modified
'as desired.
Dim i As Integer
Dim s As String
Dim nid As NOTIFYICONDATA
s = InputBox("Enter string:")
nid = setNOTIFYICONDATA(hWnd:=Form1.hWnd, _
ID:=vbNull, _
Flags:=NIF_MESSAGE Or NIF_ICON _
Or NIF_TIP, _
CallbackMessage:=vbNull, _
Icon:=Form1.Icon, _
Tip:=s)
i = Shell_NotifyIconA(NIM_MODIFY, nid)
End Sub
Private Sub Command3_Click()
'Delete an existing icon.
Dim i As Integer
Dim nid As NOTIFYICONDATA
nid = setNOTIFYICONDATA(hWnd:=Form1.hWnd, _
ID:=vbNull, _
Flags:=NIF_MESSAGE Or NIF_ICON _
Or NIF_TIP, _
CallbackMessage:=vbNull, _
Icon:=Form1.Icon, _
Tip:="")
i = Shell_NotifyIconA(NIM_DELETE, nid)
End Sub
162613 How To Manipulate Icons in the System Tray with Visual Basic
Additional query words: system tray
Keywords: kbhowto kbapi KB149276