by Eliran Abudi (BomberSoft) (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 28th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Eliran Abudi (BomberSoft)
API Declarations
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 = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim nid As NOTIFYICONDATA
Private Const WM_LBUTTONDBLCLK = &H203 'Double-click
Private Const WM_LBUTTONDOWN = &H201 'Button down
Private Const WM_LBUTTONUP = &H202 'Button up
Private Const WM_RBUTTONDBLCLK = &H206 'Double-click
Private Const WM_RBUTTONDOWN = &H204 'Button down
Private Const WM_RBUTTONUP = &H205 'Button up
Function Tray()
With nid
.cbSize = Len(nid)
.hWnd = frmTray.hWnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = frmTray.Icon
End With
Shell_NotifyIcon NIM_ADD, nid
End Function
Function Unload()
Shell_NotifyIcon NIM_DELETE, nid
End
End Function
1) Make a menu called "mnuFile".
2) Make a sub-Menu called "mnuFileExit"
3) Make a command button called "command1"
4) Make a command button called "command2"
5) Make a command button called "command3"
6) Change the property "Name" of the form to: "frmTray"
7) Copy the code
8) Have fun
Private Sub Command1_Click()
Dim ToolTipString As String
ToolTipString = InputBox("Enter the ToolTip for the App:", "Change ToolTip")
If ToolTipString <> "" Then
nid.szTip = ToolTipString & vbNullChar
Shell_NotifyIcon NIM_MODIFY, nid
End If
End Sub
Private Sub Command2_Click()
Dim sFilter As String
CommonDialog1.DialogTitle = "Select an Icon..."
sFilter = "Icon Files (*.ico)|*.ico"
sFilter = sFilter & "|Cursor Files (*.cur)|*.cur" & "|All Files (*.*)|*.*"
CommonDialog1.Filter = sFilter
CommonDialog1.ShowOpen
If CommonDialog1.FileName <> "" Then
frmTray.Icon = LoadPicture(CommonDialog1.FileName)
nid.hIcon = frmTray.Icon
Shell_NotifyIcon NIM_MODIFY, nid
End If
End Sub
Private Sub Command3_Click()
frmTray.Hide
End Sub
Private Sub Form_Load()
Tray
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim msg As Long
Dim sFilter As String
msg = X / Screen.TwipsPerPixelX
Select Case msg
Case WM_LBUTTONDOWN
Case WM_LBUTTONUP
Case WM_LBUTTONDBLCLK
frmTray.Show
Case WM_RBUTTONDOWN
PopupMenu mnuFile, , , , mnuFileExit
Case WM_RBUTTONUP
Case WM_RBUTTONDBLCLK
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload
End Sub
Private Sub mnuFileExit_Click()
Unload
End Sub