|
-
Aug 3rd, 2009, 02:07 AM
#1
Thread Starter
Lively Member
[RESOLVED] Tray icon placement
I happened to come across this code that can place an icon on the System tray. My main worry was, is t realy possible to add a menus? How?
'Declarations
Option Explicit
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 Const NIM_ADD = 0
Private Const NIM_MODIFY = 1
Private Const NIM_DELETE = 2
Private Const NIF_MESSAGE = 1
Private Const NIF_ICON = 2
Private Const NIF_TIP = 4
Private Declare Function Shell_NotifyIconA Lib "SHELL32" _
(ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Integer
'TO ADD THE ICON:
Private Sub mnuadd_Click()
' This will add the frmtray icon to the system tray
Dim retVal As Integer
Dim nid As NOTIFYICONDATA
' This creates our NotifyIconData variable
nid = setNOTIFYICONDATA( _
frmTray.hWnd, vbNull, _
NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
vbNull, frmTray.Icon, txtTip)
' Now we call our API with this variable
retVal = Shell_NotifyIconA(NIM_ADD, nid)
MDIMain.Visible = False
Me.Visible = False
End Sub
'I also used this code to delete the icon
Private Sub mnudelete_Click()
' This will delete an existing tray icon
Dim retVal As Integer
Dim nid As NOTIFYICONDATA
nid = setNOTIFYICONDATA( _
frmTray.hWnd, vbNull, _
NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
vbNull, frmTray.Icon, txtTip)
retVal = Shell_NotifyIconA(NIM_DELETE, nid)
End Sub
'The tooltip text was taken care by a text box on the form and the code for changing the icon was
Private Sub mnumodify_Click()
' This will modify an existing tray icon
Dim retVal As Integer
Dim nid As NOTIFYICONDATA
nid = setNOTIFYICONDATA( _
frmTray.hWnd, vbNull, _
NIF_MESSAGE Or NIF_ICON Or NIF_TIP, _
vbNull, frmTray.Icon, txtTip)
retVal = Shell_NotifyIconA(NIM_MODIFY, nid)
End Sub
Last edited by bentumkoitaba; Aug 3rd, 2009 at 02:10 AM.
Reason: fORGOT SOMETHING
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|